homepage Welcome to WebmasterWorld Guest from 54.205.205.47
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Exploding URL that has plus sign - quick question
tec4




msg:4394230
 3:34 am on Dec 5, 2011 (gmt 0)

Just had a question out of curiosity...

I am trying to explode my URL into an array like:

array_pop(explode("+", $_GET['id']))

but wasn't working and my MySQL query was failing because no results were picking up.

I changed the code to:

array_pop(explode(" ", $_GET['id']))

and seemed to work fine...does PHP treat "+" as a blank space when using GET? And if so, why? Does it just recognize the plus sign as a normal URL parameter "joiner" and flush it out when you use GET?

Thanks :)

 

Habtom




msg:4394272
 7:21 am on Dec 5, 2011 (gmt 0)

print/echo and see what values you are getting. For example:

$url_example = explode("+", $_SERVER['REQUEST_URI']);
print_r($url_example);

This works fine for a URL with + sign in it, and the print_r prints the array.

penders




msg:4394325
 10:49 am on Dec 5, 2011 (gmt 0)

Regardless of PHP... the "+" (plus) is a reserved character in the query part of the URL. And is used to encode a space in the querystring. PHP passes all GET values through urldecode() so the "+" gets converted (back) to a space.

In order to use a literal "+" in the querystring it needs to be encoded as "%2B". And PHP will decode this for you when read from the $_GET array.

urlencode('Hello+World') = 'Hello%2BWorld'
g1smd




msg:4394525
 8:36 pm on Dec 5, 2011 (gmt 0)

It's very important to read the HTTP specs. They define what characters are valid in domain names, paths and query strings. All three things have different rules.

lucy24




msg:4394571
 10:51 pm on Dec 5, 2011 (gmt 0)

does PHP treat "+" as a blank space when using GET

It may be more useful to look at it the other way around. A blank space in a query string is shown as + (alias %2B), which your php reads as the intended blank space. Conversely, a blank space in the body of the URL (bad! bad! bad! ;)) will change in transit into %20.

tec4




msg:4397336
 8:12 am on Dec 13, 2011 (gmt 0)

lol, ya I figured it wasn't a great way to go about it....and was getting confused when it worked with exploding an actual blank space (" ")...

Was able to modify my id in my database to explode a hyphen instead. Works like a charm and probably a better way of going about things.

I really appreciate everyone's input and explanations!

Also, started reading up on the HTTP specs. Thanks for pointing me towards the topic, g1smd :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved