Code Authors: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Code Authors Forum Index -> PHP
Author Message
Guardian
Site Admin
Site Admin



Joined: Jan 06, 2006
Posts: 4465
Location: Vsetin, Czech Republic

PostPosted: Sun Oct 10, 2010 12:00 pm Share on Linked InShare on FacebookShare on Twitter Reply with quote

Something I'm using at the moment when 'link buiding' for SEO. Although I'm already filtering strings, I like to do it again before outputting it to the browser to make sure my links are nice and clean.
When using utf-8 sometimes user input contains legitimate none English characters and if that input is an external link, or forms part of an external link, it can screw things up pretty bad if you want a nice consistent link.
Code:


function paranoia($string) {
   $specialchars = array(
   "À"=>"A",
   "Á"=>"A",
   "Â"=>"A",
   "Ã"=>"A",
   "Ä"=>"AE",
   "Å"=>"A",
   "Ā"=>"A",
   "Ă"=>"A",
   "Ą"=>"A",
   "Ǟ"=>"A",
   "Ǡ"=>"A",
   "Ǻ"=>"A",
   "Ȁ"=>"A",
   "Ȃ"=>"A",
   "Ȧ"=>"A",
   "Ḁ"=>"A",
   "Ả"=>"A",
   "Ấ"=>"A",
   "Ầ"=>"A",
   "Ẩ"=>"A",
   "Ẫ"=>"A",
   "Ậ"=>"A",
   "Ắ"=>"A",
   "Ằ"=>"A",
   "Ẳ"=>"A",
   "Ẵ"=>"A",
   "Ặ"=>"A",
   "Å"=>"A",
   "Æ"=>"AE",
   "Ǽ"=>"AE",
   "Ǣ"=>"AE",
   "Ḃ"=>"B",
   "Ɓ"=>"B",
   "Ḅ"=>"B",
   "Ḇ"=>"B",
   "Ƃ"=>"B",
   "Ƅ"=>"B",
   "Ć"=>"C",
   "Ĉ"=>"C",
   "Ċ"=>"C",
   "Č"=>"C",
   "Ƈ"=>"C",
   "Ç"=>"C",
   "Ḉ"=>"C",
   "Ḋ"=>"D",
   "Ɗ"=>"D",
   "Ḍ"=>"D",
   "Ḏ"=>"D",
   "Ḑ"=>"D",
   "Ḓ"=>"D",
   "Ď"=>"D",
   "Đ"=>"D",
   "Ɖ"=>"D",
   "È"=>"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   "ä"=>"ae",
   "ả"=>"a",
   "å"=>"a",
   "ǎ"=>"a",
   "ȁ"=>"a",
   "ȃ"=>"a",
   "ạ"=>"a",
   "ḁ"=>"a",
   "ẚ"=>"a",
   "ầ"=>"a",
   "ấ"=>"a",
   "ẫ"=>"a",
   "ẩ"=>"a",
   "ằ"=>"a",
   "ắ"=>"a",
   "ẵ"=>"a",
   "ẳ"=>"a",
   "ǡ"=>"a",
   "ǟ"=>"a",
   "ǻ"=>"a",
   "ậ"=>"a",
   "ặ"=>"a",
   "ǽ"=>"a",
   "ḃ"=>"b",
   "ɓ"=>"b",
   "ḅ"=>"b",
   "ḇ"=>"b",
   "ƀ"=>"b",
   "ƃ"=>"b",
   "ƅ"=>"b",
   "c"=>"c",
   "ć"=>"c",
   "ĉ"=>"c",
   "ċ"=>"c",
   "č"=>"c",
   "ƈ"=>"c",
   "ç"=>"c",
   "ḉ"=>"c",
   "ḍ"=>"d",
   "ḏ"=>"d",
   "ḑ"=>"d",
   "ḓ"=>"d",
   "ď"=>"d",
   "đ"=>"d",
   "ƌ"=>"d",
   "ȡ"=>"d",
   "è"=>"e",
   "é"=>"e",
   "ê"=>"e",
   "ẽ"=>"e",
   "ē"=>"e",
   "ĕ"=>"e",
   "ė"=>"e",
   "ë"=>"e",
   "ě"=>"e",
   "ȅ"=>"e",
   "ȇ"=>"e",
   "ẹ"=>"e",
   "ȩ"=>"e",
   "ę"=>"e",
   "ḙ"=>"e",
   "ề"=>"e",
   "ế"=>"e",
   "ễ"=>"e",
   "ể"=>"e",
   "ḕ"=>"e",
   "ḗ"=>"e",
   "ệ"=>"e",
   "ḝ"=>"e",
   "ǝ"=>"e",
   "ɛ"=>"e",
   "ḟ"=>"f",
   "ƒ"=>"f",
   "ǵ"=>"g",
   "ĝ"=>"g",
   "ḡ"=>"g",
   "ğ"=>"g",
   "ġ"=>"g",
   "ǧ"=>"g",
   "ɠ"=>"g",
   "ģ"=>"g",
   "ǥ"=>"g",
   "ĥ"=>"h",
   "ḣ"=>"h",
   "ḧ"=>"h",
   "ȟ"=>"h",
   "ƕ"=>"h",
   "ḥ"=>"h",
   "ḩ"=>"h",
   "ḫ"=>"h",
   "ẖ"=>"h",
   "ħ"=>"h",
   "ì"=>"i",
   "í"=>"i",
   "î"=>"i",
   "ĩ"=>"i",
   "ī"=>"i",
   "ĭ"=>"i",
   "ı"=>"i",
   "ï"=>"i",
   "ỉ"=>"i",
   "ǐ"=>"i",
   "ị"=>"i",
   "į"=>"i",
   "ȉ"=>"i",
   "ȋ"=>"i",
   "ḭ"=>"i",
   "ɨ"=>"i",
   "ḯ"=>"i",
   "ij"=>"i",
   "ĵ"=>"j",
   "ǰ"=>"j",
   "ḱ"=>"k",
   "ǩ"=>"k",
   "ḵ"=>"k",
   "ƙ"=>"k",
   "ḳ"=>"k",
   "ķ"=>"k",
   "ĺ"=>"l",
   "ḻ"=>"l",
   "ḷ"=>"l",
   "ļ"=>"l",
   "ḽ"=>"l",
   "ľ"=>"l",
   "ŀ"=>"l",
   "ł"=>"l",
   "ƚ"=>"l",
   "ḹ"=>"l",
   "ȴ"=>"l",
   "ḿ"=>"m",
   "ṁ"=>"m",
   "ṃ"=>"m",
   "ɯ"=>"m",
   "ǹ"=>"n",
   "ń"=>"n",
   "ñ"=>"n",
   "ṅ"=>"n",
   "ň"=>"n",
   "ŋ"=>"n",
   "ɲ"=>"n",
   "ṇ"=>"n",
   "ņ"=>"n",
   "ṋ"=>"n",
   "ṉ"=>"n",
   "ʼn"=>"n",
   "ƞ"=>"n",
   "ȵ"=>"n",
   "ò"=>"o",
   "ó"=>"o",
   "ô"=>"o",
   "õ"=>"o",
   "ō"=>"o",
   "ŏ"=>"o",
   "ȯ"=>"o",
   "ö"=>"oe",
   "ỏ"=>"o",
   "ő"=>"o",
   "ǒ"=>"o",
   "ȍ"=>"o",
   "ȏ"=>"o",
   "ơ"=>"o",
   "ǫ"=>"o",
   "ọ"=>"o",
   "ɵ"=>"o",
   "ø"=>"oe",
   "ồ"=>"o",
   "ố"=>"o",
   "ỗ"=>"o",
   "ổ"=>"o",
   "ȱ"=>"o",
   "ȫ"=>"o",
   "ȭ"=>"o",
   "ṍ"=>"o",
   "ṏ"=>"o",
   "ṑ"=>"o",
   "ṓ"=>"o",
   "ờ"=>"o",
   "ớ"=>"o",
   "ỡ"=>"o",
   "ở"=>"o",
   "ợ"=>"o",
   "ǭ"=>"o",
   "ộ"=>"o",
   "ǿ"=>"o",
   "ɔ"=>"o",
   "œ"=>"oe",
   "ṕ"=>"p",
   "ṗ"=>"p",
   "ƥ"=>"p",
   "ŕ"=>"p",
   "ṙ"=>"p",
   "ř"=>"p",
   "ȑ"=>"p",
   "ȓ"=>"p",
   "ṛ"=>"p",
   "ŗ"=>"p",
   "ṟ"=>"p",
   "ṝ"=>"p",
   "ś"=>"s",
   "ŝ"=>"s",
   "ṡ"=>"s",
   "š"=>"s",
   "ṣ"=>"s",
   "ș"=>"s",
   "ş"=>"s",
   "ṥ"=>"s",
   "ṧ"=>"s",
   "ṩ"=>"s",
   "ß"=>"ss",
   "ſ"=>"t",
   "ẛ"=>"t",
   "ṫ"=>"t",
   "ẗ"=>"t",
   "ť"=>"t",
   "ƭ"=>"t",
   "ʈ"=>"t",
   "ƫ"=>"t",
   "ṭ"=>"t",
   "ț"=>"t",
   "ţ"=>"t",
   "ṱ"=>"t",
   "ṯ"=>"t",
   "ŧ"=>"t",
   "ȶ"=>"t",
   "ù"=>"u",
   "ú"=>"u",
   "û"=>"u",
   "ũ"=>"u",
   "ū"=>"u",
   "ŭ"=>"u",
   "ü"=>"ue",
   "ủ"=>"u",
   "ů"=>"u",
   "ű"=>"u",
   "ǔ"=>"u",
   "ȕ"=>"u",
   "ȗ"=>"u",
   "ư"=>"u",
   "ụ"=>"u",
   "ṳ"=>"u",
   "ų"=>"u",
   "ṷ"=>"u",
   "ṵ"=>"u",
   "ṹ"=>"u",
   "ṻ"=>"u",
   "ǖ"=>"u",
   "ǜ"=>"u",
   "ǘ"=>"u",
   "ǖ"=>"u",
   "ǚ"=>"u",
   "ừ"=>"u",
   "ứ"=>"u",
   "ữ"=>"u",
   "ử"=>"u",
   "ự"=>"u",
   "ṽ"=>"v",
   "ṿ"=>"u",
   "ẁ"=>"w",
   "ẃ"=>"w",
   "ŵ"=>"w",
   "ẇ"=>"w",
   "ẅ"=>"w",
   "ẘ"=>"w",
   "ẉ"=>"w",
   "ẋ"=>"x",
   "ẍ"=>"x",
   "ỳ"=>"y",
   "ý"=>"y",
   "ŷ"=>"y",
   "ỹ"=>"y",
   "ȳ"=>"y",
   "ẏ"=>"y",
   "ÿ"=>"y",
   "ỷ"=>"y",
   "ẙ"=>"y",
   "ƴ"=>"y",
   "ỵ"=>"y",
   "ź"=>"z",
   "ẑ"=>"z",
   "ż"=>"z",
   "ž"=>"z",
   "ȥ"=>"z",
   "ẓ"=>"z",
   "ẕ"=>"z",
   "ƶ"=>"z",
   "/"=>"-",
   ","=>"-",
   ","=>"-",
   ";"=>"-",
   " "=>"-");
   $string = strtr($string,$specialchars);
   $string = preg_replace("/&([a-zA-Z])(uml|acute|grave|circ|tilde|ring),/","",$string);
   $string = preg_replace("/[^a-zA-Z0-9_.-]/","",$string);
   $string = str_replace(array('---','--'),'-', $string);
   $string = str_replace(array('..','.'),'', $string);
   return $string;
  }

_________________
TPD 
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    Code Authors Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

 
Forums ©
linear-bunch
linear-bunch