Jump to content

Recommended Posts

Heres my code:

 


<?php
$code=$_POST['code'];

$code2 = str_replace('"','\"',$code);
$code2 = str_replace('\\"','\"',$code);

?>

<form id="form1" name="form1" method="post" action="convcod.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 "$code2"; ?></td>
  </tr>
  <tr align="right">
  <td><br /><input type="submit" value="Convert" /></td>
  </tr>
</table>
</form>

 

 

What im trying to do is change say

<input type="hidden" name="sectionid" value="5" />

to

<input type=\"hidden\" name=\"sectionid\" value=\"5\" />

or

<table width="100%" border="0" cellspacing="0" cellpadding="2">

to

<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">

 

Basicly changeing all " to \"

 

I've got it to do that but when i try and echo the new code, it echos the actual table and not the code. I need to it echo the actual code not display a table or input field... any help is greatly appreciated!!!!

Link to comment
https://forums.phpfreaks.com/topic/42077-str-replace-help-urgent/
Share on other sites

Your going about that the wrong way. You need to change < to be < Try this:

 


<?php
$code=$_POST['code'];

$code2 = str_replace('<','<',$code);

?>

<form id="form1" name="form1" method="post" action="convcod.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 "$code2"; ?></td>
  </tr>
  <tr align="right">
  <td><br /><input type="submit" value="Convert" /></td>
  </tr>
</table>
</form>

 

Hopefully that is what you want.

 

--FrosT

Ah try this:

 


<?php
$code=$_POST['code'];

$code2 = str_replace('<','<',$code);
$code2 = addslashes($code2);
?>

<form id="form1" name="form1" method="post" action="convcod.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 "$code2"; ?></td>
  </tr>
  <tr align="right">
  <td><br /><input type="submit" value="Convert" /></td>
  </tr>
</table>
</form>

 

can be viewed here: http://www.aeonity.com/tstJs.php

 

--FrosT

The function the OP is looking for is htmlentities().

<form id="form1" name="form1" method="post" action="convcod.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 htmlentities($_POST['code'],ENT_QUOTES); ?></td>
  </tr>
  <tr align="right">
  <td><br /><input type="submit" value="Convert" /></td>
  </tr>
</table>
</form>

 

Ken

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.