How To Remove Special Characters From Urls HTML PHP Link Linking Removing
Posted On Sun Apr 08, 2007 By hostman In PHP Forums And Topics Discussions About Hyper Text Programming Language Forums
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:
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.
! @ # $ % ^ & * ( ) _ + { } | : " < > ? [ ] \ ; ' , . / / * - + ~ ` - = 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(' ','--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
$code_entities_replace = array('-','-','','','','','','','','','','','','','','','','','','','','','','','','');
$text = str_replace($code_entities_match, $code_entities_replace, $text);
return $text;
}
?>
# 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(' ','--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
$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.
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
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.
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.........!
its very useful.........!
sezer Tue Jun 17, 2008
html special characters --
html-lesson.blogspot /2008/06/special-characters.html
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
thanks
AbhinavZone Fri Nov 23, 2007
hey thanx buddy!!! gr8 post
Related Content
Information
Forums »
PHP Forums And Topics Discussions About Hyper Text Programming Language »
How To Remove Special Characters From Urls HTML PHP Link Linking Removing
PHP Forums And Topics Discussions About Hyper Text Programming Language »
How To Remove Special Characters From Urls HTML PHP Link Linking Removing
Title: How To Remove Special Characters From Urls HTML PHP Link Linking Removing
Description: How To Remove Special Characters From Urls HTML PHP Link Linking Removing
Tags: how ,to ,remove ,special ,characters ,from ,urls ,html ,php ,link ,linking ,removing
Info: This Post Has Been Viewed 0 Times Since
Date: Sun Apr 08, 2007
Author hostman Received 15 Replies #1016
Date: Sun Apr 08, 2007
Author hostman Received 15 Replies #1016
Share
URL: 

Embed: 

To embed this topic, just copy the code from the "Embed" box. Once you've copied the code, just paste it into your website or blog to embed it
BBCODE:: 

BBCODE is use on forums. You can put this code on all your BBCODE enabled forums like PhpBB, vBulletin® and others. Just Copy and Paste this code on your Posts and Replies on your forums
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
copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5

