dsaba Posted April 9, 2007 Share Posted April 9, 2007 i have this error code unexpected T STRING on this line: str_replace(addslashes('onmouseover="showImg('name', 'tabla_novedades2', 's_asc.png', 'img1');"'), addslashes('onmouseover="showImg('name', 'tabla_novedades2', 's_desc.png', 'img1');"'), $td_name); i tried escaping slashes with the addslashes function but obviously this did not work there is a ";" in the string so i know that is causing the error I am replacing this string: 'onmouseover="showImg('name', 'tabla_novedades2', 's_asc.png', 'img1');" with this string: 'onmouseover="showImg('name', 'tabla_novedades2', 's_desc.png', 'img1');" how do I do this with no errors with the str_replace function?? Link to comment https://forums.phpfreaks.com/topic/46225-solved-escaping-single-quotes-double-quotes-and-semicolons-with-str_replace/ Share on other sites More sharing options...
kenrbnsn Posted April 9, 2007 Share Posted April 9, 2007 In these cases you need to manually escape the quotes. The semi-colon has nothing to do with the error. It's having unescaped single quotes inside a string delimited by single quotes. Try this: <?php str_replace('onmouseover="showImg(\'name\', \'tabla_novedades2\', \'s_asc.png\', \'img1\');"', 'onmouseover="showImg(\'name\', \'tabla_novedades2\', \'s_desc.png\', \'img1\');"', $td_name); ?> It might be easier just to do: <?php str_replace('s_asc.png','s_desc.png',$td_name); ?> Ken Link to comment https://forums.phpfreaks.com/topic/46225-solved-escaping-single-quotes-double-quotes-and-semicolons-with-str_replace/#findComment-224738 Share on other sites More sharing options...
btherl Posted April 9, 2007 Share Posted April 9, 2007 It's a matter of style, but I prefer using temporary variables to nested functions. Instead of func(func2($a), func2($b)); you can use $f_a = func2($a); $f_b = func2($b); func($f_a, $f_b); The second version is also easier for debugging for 2 reasons: 1. You can print out intermediate values. 2. The line number of the error will specify one function, not one set of nested functions. Link to comment https://forums.phpfreaks.com/topic/46225-solved-escaping-single-quotes-double-quotes-and-semicolons-with-str_replace/#findComment-224745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.