How do you Replace "\" by "(nothing)"?

Member Avatar

diafol

Try:

echo stripslashes($str);

But that'll only work with certain combos. Using it to replace \n etc won't work as expected. To get around most of these problems, enclose the string in single quotes '...'.

$str = 'wkvcw\swfvwnl';

But what does this mean?

$str = 'wkvcw\swfvwnl';

But what does this mean?

An example

I dont understand can this replace evrything in a php page.
if i put this in a php page?
I'm knew to php.

Member Avatar

diafol

What do you mean change everything in a php page? I assumed you meant change a small string as in the contents of a variable. What are you trying to do? Show your code so far or at least what you're trying to change. Accurately describing your problem will avoid ping-pong discussions.

Id like to replace "\" in a php page with this html code in it:

<div id=shadow><b>anonymous </b> on Sunday 10 June 2012  at 15:25 GMT wrote:</br></br> <div style=\"text-align: center;\"><img alt=\"\" src=\"http://image.com\" align=\"none\"><br>test<br></div></div></br>

Is it possible?

Member Avatar

diafol

try:

$file = "myfile.php";
$str = stripslashes(file_get_contents($file));
echo $str;

May be unpredictable w.r.t results - perhaps a more focussed replace of \' or \" would be better?

commented: Great +0