I have this simple PHP variable :
$Title = $_POST['text'];
and when it has this input : here's the text
the PHP will recognize as this when it written to a file : here\'s the text
$Filename = 'index.php';
$Handle = fopen($Filename, "r");
$Contents = fread($Handle, filesize($Filename));
fclose($Handle);
$TitleTag = extractor($Contents, "<title>", "</title>");
$Contents = str_replace ($TitleTag, $Title, $Contents);
$Handle = fopen($Filename, 'w+');
fwrite($Handle, $Contents);
fclose($Handle);
how to get exactly just like what user typed? thanks
The quick and simple fix would be:
see the docs
Alternatively, you could have php treat the contents as a string format, which will return the escaped characters correctly, too:
But be weary, if there is a
%char somewhere in your code, it’ll have to be doubled, if notsprintfwill treat it as a place-holder:This, then, requires two operations and is not the best approach, especially since I get the impression you’re treating an HTML string (
style='width:50%'<– not entirely unlikely)