Jump to content

[SOLVED] str_replace func help please


Patrick3002

Recommended Posts


<?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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.