Wallpapers Forums Login

How To Remove Special Characters From Urls HTML PHP Link Linking Removing

today i came across someting which i use frequently for all of my mod_rewrite urls. I had this web site that wanted the title on their url but i noticed that some titles had weird special characters you find on your keyboard for example some of them are these

! @ # $ % ^ & * ( ) _ + { } | : " < > ? [ ] \ ; ' , . / / * - + ~ ` - = space


so lets say for example i have a page title called:
I am this @ thisdomain.com! [contact] & phone # (213) 555-1212

as you can see from my example title, i would have to make the url look like this:
I am this @ thisdomain.com! [contact] & phone # (213) 555-1212.html

That just wouldn't work, how about if i could make it look like this:
i-am-this-thisdomain-com-contact-phone-213-555-1212.html

So how can you do this. Well, if you have PHP you can very easy. So I created a function to make this possible and this is the script code:
CODE:
<?php
# This function makes any text into a url frienly
# This script is created by wallpaperama.com
function clean_url($text)
{
$text=strtolower($text);
$code_entities_match = array(' ','--','&quot;','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
$code_entities_replace = array('-','-','','','','','','','','','','','','','','','','','','','','','','','','');
$text = str_replace($code_entities_match, $code_entities_replace, $text);
return $text;
}
?>


This function will make your url look shorter and it will be search engine friendly. it will remove all those unwantd spcial characters you find on your keyboard above the number 1234567890 and some others, this way you links witll look better and liking to them will be easier by removing all the unwanted special strings with a simple php function snippet wiget in your html web pages.

NOTE: this will only work if you have php, if you don't you can visit our friends at www.webune.com and sign up with on of their PHP web hosting plans.
deo Thu Jul 21, 2011
21-1039-thumb3-constantine.jpeg
thanx dude it's working
Tom Mon Nov 01, 2010
- at - mojtaba

Why do u str_replace a space by a space twice?
$str = str_replace(" ", " ", $var);

I agree urs can be good just dont understand that bit.

Furtheron very good website i like ur solution
Bill Tue Sep 14, 2010
Great bit of code. Thanks for the info, really helps to have so many great resources.
mojtaba Sat Jul 10, 2010
10-1039-f-102910952-ba5d91d3.jpeg
$var = $keyword;
$str = str_replace(" ", " ", $var);
$stripped = ereg_replace("[^A-Za-z0-9 ]", "", $str);

$str1 = str_replace(" ", " ", $stripped);
<a href="filesharepoi
Tam Tue Jun 15, 2010
Awesome. This totally helped me out. Thanks
kishore Mon Mar 29, 2010
great dude....thanx a lot...from last 10 days i was struggling 4 this code..but, try to add SEO 4 ur site...because in google this is not - at - 1st page....my intention is no user can miss this site...
Jonah Thu Mar 05, 2009
Wouldn't a simple preg_replace string be easier?
komaghan Fri Oct 31, 2008
hi u don a great job in php
unknown Sat Oct 18, 2008
to be able under all circumstances to practice five things constitutes perfect virtue; these five things are gravity, generosity of soul, sincerity, earnestness and kindness.
sundar Mon Oct 06, 2008
hi,
its very useful.........!
Amjith Mon Sep 22, 2008
20080923-71738-aaa.jpg
thanks dude
sezer Tue Jun 17, 2008
html special characters --
html-lesson.blogspot /2008/06/special-characters.html
KCJ-pop Wed Jan 09, 2008
thank you so much for this useful function. i googled it for a while and i found here. thank again. keep up your good job!
Prashant Thu Dec 06, 2007
excellent. very good example.

thanks
AbhinavZone Fri Nov 23, 2007
hey thanx buddy!!! gr8 post

Related Content

Information

Share

wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5