Jump to content


Photo

Need help with \ being loaded before a '


  • Please log in to reply
4 replies to this topic

#1 mazman13

mazman13
  • Members
  • PipPipPip
  • Advanced Member
  • 156 posts

Posted 12 September 2006 - 06:00 AM

I'm saving text to a TEXT file instead of a database, so if i use "" or '' to say something, PHP adds the \ before it.

I've tried the stripslashes($string) before it loads to the text file and when I call the info (not both at the same time)...but the \ is still there.

Any ideas?

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 12 September 2006 - 08:31 AM

you may have added slashes twice to the database...
try

$string=str_replace("\",'',$string);
echo $string;

that should do the job..


Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 12 September 2006 - 08:41 AM

<?php

function magic_strip($str)
{
    if (get_magic_quotes_gpc()) $str = stripslashes($str);

    return $str;
}

$file = fopen('/path/to/file.txt', 'w');

frwite($file, magic_strip($_POST['text']));

fclose($file);

?>


#4 mazman13

mazman13
  • Members
  • PipPipPip
  • Advanced Member
  • 156 posts

Posted 12 September 2006 - 03:42 PM

That script works. Thanks.

Can you explain it? I think I have an idea, but I just want to make sure.

#5 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 12 September 2006 - 05:00 PM

you only need to stripslashes() post data if magic_quotes are on :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users