PHP How To Remove Plus Space Percent Special Characters From URLs Code

RegisterLogin
PHP How To Remove Plus Space Percent Special Characters From URLs Code
Post Description: PHP How To Remove Plus Space Percent Special Characters From URLs Code
Tags: PHP, How, To, Remove, Plus, Space, Percent, Special, Characters, From, URLs, Code
This Post Was Posted On Feb 29, 2008 By mickey #1218
have you ever noticed that some websites use the plus sign (+) in their urls. i've een some site that also have the %20 (percentage sign character) in the urls to be used for the space character. today wanted to change a url into a string but couldn't figure out how to remove them. i found different way to remove the plus sign from the url string, but the best way to remove the plus sign from the url is with the url decode function in PHP. so today in this little tutorial i will show you how you can remove the + sing from a url with a sample code.

by the way, thanks for the folks at www.webune.com for their support on this question. i am writing this short tutorial here just in case anyone who may have a question like may also have this same question.

so in my example, lets say i have this url:
http://www.wallpaperama.com/search/?q=free+wallpapers+at+wallpaperama&meta=3&lan=en

ok, to make it simple and easy to strip the plus sign off the url, i could use this code:


     Code:
#declare the $url string
$url = "http://www.wallpaperama.com/search/?q=free+wallpapers+at+wallpaperama&meta=3&lan=en";

# Get the + out of the url
$url = urldecode($url);

#display the $url string
echo $url;


so the ouput will look like this:

http://www.wallpaperama.com/search/?q=free wallpapers at wallpaperama&meta=3&lan=en

try it yourself, you'll see that it works. The only thing you need is a text editor like notepad and PHP hosting.

if you have windows you can use notepad, if you are using linux you can use nano or VI, whichever you prefer.

the other thing you are going to need is PHP hosting. if you don't have PHP on your site, you can get PHP hosting from our friends at www.webune.com

hope this has helped you. any comments are welcome.

also, if for some reason you want to add the plus sign on the url, the change the line:

FROM:
     Code:
$url = urldecode($url);

TO:
     Code:
$url = urlencode($url);
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
muneco
#1656 1
this works. i was trying to strip out the keyword for this url: search?hl=en&q=my+search+keyword&btnG=Search and i followed your instructions and i was able to get the "my search keyword
Feb 05, 2007 Reply Report abuse
©2011 Webune Forums - Tue Dec 20, 2011 5:47 am
Powered by: Webune Forums V3