the dreaded \

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
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

the dreaded \

Post 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
Last edited by ziggy1621 on Thu Aug 03, 2006 10:15 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

Pimptastic wrote:stripslashes()
i'll look it up, but for time's sake, where do i put it.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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.
ziggy1621
Forum Commoner
Posts: 37
Joined: Mon Sep 12, 2005 5:12 pm

Post by ziggy1621 »

i got it with this

$string = stripslashes($text);

thanks
Post Reply