Why so many backslashes??

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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Why so many backslashes??

Post by Luke »

I am making a directory administration panel for my site, and the description line always somes up like this if there are apostrophies and I have to submit, and fix errors a bunch of times. I think it has something to do with the urlencode function because every time you submit it, it adds more backslashes. here is the code where it is printed:

Code: Select all

<tr>
     <td>Description of Business</td>
     <td><textarea type="text" class="<?php echo $_GET['e_desc'] ?>_text" name="desc" rows="4" cols="20" /><?php echo stripslashes($_GET['desc']) ?></textarea></td>
    </tr>
and the php function that encodes the url

Code: Select all

function make_query($array, $negate="NONE"){
    $query_string = "&";
    foreach($array as $key => $val){
        if($key != $negate && is_array($val)){
	        foreach($val as $k => $v){
	    		$query_string .= urlencode($key) . $k . "=" . $v . "&";
    		}
        }
        elseif($key != $negate){
            $query_string .= urlencode($key)."=".urlencode($val)."&";
        }
    }
    $query_string = substr($query_string, 0, -1);
    return $query_string;
}
and here is what I get
asd df \\\\\\\'asd\\\\\\\'fa\\\\\\\' sdf \\\\\\\'asdf\\\\\\\' asd\\\\\\\'f asd\\\\\\\'f a\\\\\\\'sdf
I can't really explain it any better than that... so sorry if it is confusing
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

gpc_magic_quotes is turned on ;)

Turn it off or use stripslashes() -- In the right places.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

alright...

Can I turn the magic quotes thing with ini_set?

I used stripslashes (if you look at the code above). Was it in the wrong place?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

The Ninja Space Goat wrote:alright...

Can I turn the magic quotes thing with ini_set?
You could always try it ;) Hint Hint.

BTW... You want to stripslashes when the data is retreived FROM the textarea rather than when you put it back -- At least I've always done that but logically I dont see a difference :?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

thanks d11...

edit: ok I tried ini_set("magic_quotes_gpc", 0); and that did nothing... I will try a few more things with that...
Last edited by Luke on Mon Dec 12, 2005 3:00 pm, edited 2 times in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Oh BTW... typo on my part (and memory loss :P)

It's magic_quotes_gpc not gpc_magic_quotes
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

d11wtq wrote:You want to stripslashes when the data is retreived FROM the textarea
This worked... Thanks man,
Post Reply