fwrite adds slashes to " "
Moderator: General Moderators
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
fwrite adds slashes to " "
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.
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.
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
Add it around the variable you want to strip the slashes from
ex 1.
ex 2.
ex 1.
Code: Select all
echo stripslashes($var)Code: Select all
fwrite($handle, stripslashes($var))- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
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
"/ 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
Last edited by josh on Thu Feb 02, 2006 1:19 am, edited 1 time in total.
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.
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
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";
}
}- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
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()
Code: Select all
echo get_magic_quotes_gpc();- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Ah, so I was right..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"
stripslashes() is your friend.