Patrick3002 Posted March 13, 2007 Share Posted March 13, 2007 <?php $code=$_POST['code']; $code2 = str_replace('<','<',$code); $code3 = addslashes($code2); ?> <form id="form1" name="form1" method="post" action="convert.php"> <table width="737" height="566" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="737" align="left" valign="top"> <textarea name="code" cols="120" rows="35" wrap="VIRTUAL"></textarea> </td> </tr> <tr> <td><?php echo "$code3"; ?></td> </tr> <tr align="right"> <td><br /><input type="submit" value="Convert" /></td> </tr> </table> </form> That code is supposed to change all " to \". If i run... <form id="form1" name="form1" method="post" action="convert.php"> <table width="737" height="566" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="737" align="left" valign="top"> <textarea name="code" cols="120" rows="35" wrap="VIRTUAL"></textarea> In the script, it outputs... <form id=\\\"form1\\\" name=\\\"form1\\\" method=\\\"post\\\" action=\\\"convert.php\\\"> <table width=\\\"737\\\" height=\\\"566\\\" border=\\\"0\\\" cellpadding=\\\"0\\\" cellspacing=\\\"0\\\"> <tr> <td width=\\\"737\\\" align=\\\"left\\\" valign=\\\"top\\\"> <textarea name=\\\"code\\\" cols=\\\"120\\\" rows=\\\"35\\\" wrap=\\\"VIRTUAL\\\"></textarea> Why is it adding so many slashes?? I just need it to add one slash not 3...heh any help is greatly appreciated!! Link to comment https://forums.phpfreaks.com/topic/42495-solved-str_replace-func-help-please/ Share on other sites More sharing options...
Orio Posted March 13, 2007 Share Posted March 13, 2007 That's because you've got magic_quotes enabled... Change the addslashes() line to: <?php if(!get_magic_quotes_gpc()) $code3 = addslashes($code2); else $code3 = $code2; //Or in the shorter version... $code3 = (get_magic_quotes_gpc()) ? $code2 : addslashes($code2); ?> Orio. Link to comment https://forums.phpfreaks.com/topic/42495-solved-str_replace-func-help-please/#findComment-206165 Share on other sites More sharing options...
Patrick3002 Posted March 13, 2007 Author Share Posted March 13, 2007 Works!! Thank you so much Link to comment https://forums.phpfreaks.com/topic/42495-solved-str_replace-func-help-please/#findComment-206169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.