- Forums
- PHP
- How To Remove Special Characters From Urls HTML PHP Link Linking Removing
This Page Contains information about How To Remove Special Characters From Urls HTML PHP Link Linking Removing By wallpaperama in category PHP with 15 Replies. [1016], Last Updated: Sat May 18, 2024
wallpaperama
Sun Apr 08, 2007
15 Comments
11958 Visits
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
! @ # $ % ^ & * ( ) _ + { } | : " < > ? [ ] \ ; ' , . / / * - + ~ ` - = spaceso lets say for example i have a page title called:
I am this @ thisdomain.com! [contact] & phone # (213) 555-1212as 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.htmlThat just wouldn't work, how about if i could make it look like this:
i-am-this-thisdomain-com-contact-phone-213-555-1212.htmlSo 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 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.