prob with replacing "

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gi7mo!
Forum Newbie
Posts: 4
Joined: Sat Aug 02, 2003 9:58 am

prob with replacing "

Post by Gi7mo! »

i build an cms.... for a website....
but if i save the text wich the user has typed and there is an " in the php replaces me the " to an \"
the i wrote a little script to replace that...
but now php makes me out of the " an ""

heres the code...
$copytext = the text wich i want to save

[syntax=php]$a = chr(34); //assign ascii \
$b = chr(92); //assign ascii "
$c = $a.$b; //merge ascii \"
$d = "&quot";
$e = chr(59); //assign ascii ;
$f = $d.$e; //merge
$g = chr(7); //assign ascii linefeed
$h = explode($g, $copytext); //delete linefeed
$w = str_replace($b, $f, $h); //replace \" -> "
$z = "../_base_include/";
$z .= $save;
$z .= ".txt";
$x = fopen($z , "w");
$test = $w[0];
fwrite($x, $test);
fclose($x);[/syntax]

can anyone tell me what is wrong with it ?!?
User avatar
Gianni_T
Forum Newbie
Posts: 8
Joined: Fri Aug 01, 2003 12:47 am
Location: Bari, Italy
Contact:

Post by Gianni_T »

Gi7mo!
Forum Newbie
Posts: 4
Joined: Sat Aug 02, 2003 9:58 am

Post by Gi7mo! »

u missunderstand me...
i don't want these slashes before the " ....
i want to remove them, because it is for an website...
and it looks a little dumb if there is an \" visible for the user....
User avatar
Gianni_T
Forum Newbie
Posts: 8
Joined: Fri Aug 01, 2003 12:47 am
Location: Bari, Italy
Contact:

Post by Gianni_T »

Sorry :oops: ,
perhaps you are interested in "stripslashes"
http://it.php.net/manual/en/function.stripslashes.php
Gi7mo!
Forum Newbie
Posts: 4
Joined: Sat Aug 02, 2003 9:58 am

Post by Gi7mo! »

np män, but now he only gives me an R back.....

$x = fopen($z , "w");
$v = stripslashes($x);
$xy = $v[0];
fwrite($x, $xy);
fclose($x);

<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>.....
:cry:
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

fopen gives you back a file pointer, not the contents of the file, you want to look at the fread or similar functions to get the contents of the file into a variable before calling stripslashes.
Gi7mo!
Forum Newbie
Posts: 4
Joined: Sat Aug 02, 2003 9:58 am

Post by Gi7mo! »

thanks a very very lot män...
it works !!!!
:D *smile*
Post Reply