Я обычно сохраняю очень мало на строку, т.е.:
select
col1,
col2,
col3
from
some_table tabl1
where
col1 = 'some'
and
(
col2 = 'condition'
or col2 = 'other'
)
Почему бы просто не сделать это:
$word = htmlentities(str_replace($search, $replace, $word), ENT_QUOTES);
?