1

I have to generate a php file from the content of a div, this is working. But characters like < and > are blocking the generation.

For example :

<div id="test">
<p> I want to have this in my php file &lt;?php echo "tatata" ?&gt; </p>
</div>

I'm using the function $("#test").html() to get the content before to send it to a php file using ajax.

If I do an alert of this, I get the correct data but when I open the php file generated, I only have :

<div id="test">
<p> I want to have this in my php file

I've tried to use &#60 instead of &lt; I dont know if the problem comes from jQuery or the php code I call with ajax.

But I'm sure the problem is due to the < and > characters, because when I remove them, it works correctly.

Thanks for your help !

Spydaxx
  • 23
  • 8

2 Answers2

1

The suggestion of @treyBake is working perfectly.

As he suggested in the comments, the function str_replace solved the problem. I use it just before to create my php file and it's working.

Thank you @treyBake ! :)

Spydaxx
  • 23
  • 8
0

Have you tried using htmlentities?

e.g.

echo htmlentities('&lt;sometext&gt;');
treyBake
  • 6,277
  • 6
  • 25
  • 54
Dan Gribble
  • 106
  • 1
  • 8