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

RegisterLogin
How To Remove Special Characters From Urls HTML PHP Link Linking Removing
Post 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
This Post Was Posted On Feb 29, 2008 By web hosting #1229
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.
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
KCJ-pop
#1671 1
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!
Jan 09, 2008 Reply Report abuse
Prashant
#1670 2
excellent. very good example.

thanks
Dec 06, 2007 Reply Report abuse
AbhinavZone
#1669 3
hey thanx buddy!!! gr8 post
Nov 23, 2007 Reply Report abuse
Leave Your Comments...
©2011 Webune Forums - Wed Dec 21, 2011 4:00 am
Powered by: Webune Forums V3