Page 1 of 1
fwrite adds slashes to " "
Posted: Wed Feb 01, 2006 9:10 pm
by nickman013
Hello,
I have a fwrite script that adds / (slashes) to my written data if there is a " so if somebody writes:
Nicky said "yo yo yo" it will out put Nicky Said "/ yo yo yo"/
Is there a way to stop that?
Thank You.
Posted: Wed Feb 01, 2006 9:18 pm
by neophyte
Post your code...
Posted: Wed Feb 01, 2006 9:23 pm
by josh
stripslashes()
Posted: Wed Feb 01, 2006 9:56 pm
by nickman013
I dont have my code because I am not home right now.
Jshpro, where would I add that stripslashes() to?
If you need my code I will post soon. It is just a basic fwrite script.
Posted: Thu Feb 02, 2006 12:40 am
by josh
Add it around the variable you want to strip the slashes from
ex 1.
ex 2.
Code: Select all
fwrite($handle, stripslashes($var))
Posted: Thu Feb 02, 2006 12:46 am
by AKA Panama Jack
jshpro2 wrote:stripslashes()
That doesn't strip forward slashes only back slashes.
Posted: Thu Feb 02, 2006 1:17 am
by josh
Well the text he pasted does contain foward slashes:
"/ yo yo yo"/
however nothing standard in PHP will produce that effect, the closest match for the symptom he is experiencing is magic_quotes, which leads me to beleive the string he posted is an example and he probably meant \" yo yo yo \"
He had already been asked to show his code I was giving him something to try to see if we can skip that step, if it didn't work then its no big deal, just following you through my logic here
Posted: Thu Feb 02, 2006 1:17 am
by m3mn0n
My guess is he used the wrong slash when describing the problem... if that isn't the case, then creating a function to replace or remove the slashes is best. It could utilize either
str_replace(),
preg_replace(), or as jshpro2 mentioned,
stripslashes(), but if you're going to use stripslashes(), you'd need to use str_replace() to make it able to work, but at that point, the need to do the extra step is unnecessary...doing it just with str_replace() is fine in that case.
Posted: Thu Feb 02, 2006 3:15 pm
by nickman013
Here is my script.
Code: Select all
$content = "
<tr><td><b>$name</b> voted this muot as a $vote !<br><b>$name said $comments</td></tr>
";
$filename = '/home/muot/public_html/pages/voting/comments.txt';
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $content) === FALSE) {
echo "Cannot write to file ($somecontent)";
exit;
}
echo "";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
}
Posted: Thu Feb 02, 2006 3:17 pm
by raghavan20
put this at the top of the script to see magic quotes is enabled..
if enabled, you have to use strip slashes using stripslashes() and provide backslashes using mysql_real_escape_string()
Posted: Thu Feb 02, 2006 3:43 pm
by m3mn0n
Can you clarify if it was forward or backward slashes?
Posted: Thu Feb 02, 2006 3:53 pm
by nickman013
Frank Rafner voted this muot as a 4 !
Frank Rafner said Omg this is a enjoyable muot. When I am 80 years old the words of greg will echo through my head \"Oh my God frank him self\"
Posted: Thu Feb 02, 2006 3:56 pm
by raghavan20
nickman013 wrote:
Frank Rafner voted this muot as a 4 !
Frank Rafner said Omg this is a enjoyable muot. When I am 80 years old the words of greg will echo through my head "Oh my God frank him self"
i hope this is POST or GET data...is not it?
Posted: Thu Feb 02, 2006 5:50 pm
by m3mn0n
nickman013 wrote:
Frank Rafner voted this muot as a 4 !
Frank Rafner said Omg this is a enjoyable muot. When I am 80 years old the words of greg will echo through my head "Oh my God frank him self"
Ah, so I was right..
stripslashes() is your friend.