Page 1 of 1

the dreaded \

Posted: Thu Aug 03, 2006 10:13 am
by ziggy1621
i've got a textarea that submits its information to a text file, but when it submits anything with single or double quotes, php automatically puts the \ infront of the quotes. Is there a way to stop that?

I've got php pulling the textfile like this:

Code: Select all

<?
$filename = "home.txt"; 
$content_array = file($filename);
$content = implode("", $content_array);
print nl2br($content);
?>
and submitting it using fput

Code: Select all

<?php
$text=$_REQUEST['text'];
$filename ="../home.txt";    
$myFile= fopen($filename,'w+');    
$string = "$text";
fputs($myFile, $string);   
fclose($myFile);       
?>
it puts the file fine, just need to get rid of the /

thanks

Posted: Thu Aug 03, 2006 10:14 am
by JayBird

Posted: Thu Aug 03, 2006 10:15 am
by ziggy1621
Pimptastic wrote:stripslashes()
i'll look it up, but for time's sake, where do i put it.

Posted: Thu Aug 03, 2006 10:19 am
by Benjamin
Found this in the manual. Will be useful if you cannot turn off magic_quotes.

Code: Select all

if(get_magic_quotes_gpc() || ini_get('magic_quotes_sybase'))
{
    $_GET =     magic_quotes_strip($_GET);
    $_POST =    magic_quotes_strip($_POST);
    $_COOKIE =  magic_quotes_strip($_COOKIE);
    $_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
    $_FILES =   magic_quotes_strip($_FILES);
    $_ENV =     magic_quotes_strip($_ENV);
    $_SERVER =  magic_quotes_strip($_SERVER);
}

function magic_quotes_strip($mixed)
{
    if(is_array($mixed))
    {
        return array_map('magic_quotes_strip', $mixed);
    }

    return stripslashes($mixed);
}
This would go at the top of every page.

Posted: Thu Aug 03, 2006 10:20 am
by ziggy1621
i got it with this

$string = stripslashes($text);

thanks