{"id":355,"date":"2010-10-06T16:13:27","date_gmt":"2010-10-07T00:13:27","guid":{"rendered":"http:\/\/blog.portnumber53.com\/?p=355"},"modified":"2010-10-06T16:13:27","modified_gmt":"2010-10-07T00:13:27","slug":"php-function-to-clean-string-for-seo-usage-2","status":"publish","type":"post","link":"https:\/\/blog.portnumber53.com\/index.php\/2010\/10\/06\/php-function-to-clean-string-for-seo-usage-2\/","title":{"rendered":"php:\/\/ function to clean string for SEO usage"},"content":{"rendered":"<p>If you need a good function to clean strings to use them as URLs for SEO purposes, here&#8217;s a suggestion:<\/p>\n<pre class=\"brush:php\">function chunk_special_chars($string)\u00a0{\n  $normalizeChars = array(\n    '\u0160'=&gt;'S', '\u0161'=&gt;'s', '\u00d0'=&gt;'Dj','\u017d'=&gt;'Z', '\u017e'=&gt;'z', '\u00c0'=&gt;'A', '\u00c1'=&gt;'A', '\u00c2'=&gt;'A', '\u00c3'=&gt;'A', '\u00c4'=&gt;'A',\n    '\u00c5'=&gt;'A', '\u00c6'=&gt;'A', '\u00c7'=&gt;'C', '\u00c8'=&gt;'E', '\u00c9'=&gt;'E', '\u00ca'=&gt;'E', '\u00cb'=&gt;'E', '\u00cc'=&gt;'I', '\u00cd'=&gt;'I', '\u00ce'=&gt;'I',\n    '\u00cf'=&gt;'I', '\u00d1'=&gt;'N', '\u00d2'=&gt;'O', '\u00d3'=&gt;'O', '\u00d4'=&gt;'O', '\u00d5'=&gt;'O', '\u00d6'=&gt;'O', '\u00d8'=&gt;'O', '\u00d9'=&gt;'U', '\u00da'=&gt;'U',\n    '\u00db'=&gt;'U', '\u00dc'=&gt;'U', '\u00dd'=&gt;'Y', '\u00de'=&gt;'B', '\u00df'=&gt;'Ss','\u00e0'=&gt;'a', '\u00e1'=&gt;'a', '\u00e2'=&gt;'a', '\u00e3'=&gt;'a', '\u00e4'=&gt;'a',\n    '\u00e5'=&gt;'a', '\u00e6'=&gt;'a', '\u00e7'=&gt;'c', '\u00e8'=&gt;'e', '\u00e9'=&gt;'e', '\u00ea'=&gt;'e', '\u00eb'=&gt;'e', '\u00ec'=&gt;'i', '\u00ed'=&gt;'i', '\u00ee'=&gt;'i',\n    '\u00ef'=&gt;'i', '\u00f0'=&gt;'o', '\u00f1'=&gt;'n', '\u00f2'=&gt;'o', '\u00f3'=&gt;'o', '\u00f4'=&gt;'o', '\u00f5'=&gt;'o', '\u00f6'=&gt;'o', '\u00f8'=&gt;'o', '\u00f9'=&gt;'u',\n    '\u00fa'=&gt;'u', '\u00fb'=&gt;'u', '\u00fd'=&gt;'y', '\u00fd'=&gt;'y', '\u00fe'=&gt;'b', '\u00ff'=&gt;'y', '\u0192'=&gt;'f'\n  );\n  $string = strtr($string, $normalizeChars);\n  $string = str_replace('&amp;', '-and-', $string);\n  $string = trim(preg_replace('\/[^wd_ -]\/si', '', $string));\/\/remove all illegal chars\n  $string = str_replace(' ', '-', $string);\n  $clean = iconv('UTF-8', 'ASCII\/\/TRANSLIT', $string);\n  $clean = preg_replace(\"\/[^a-zA-Z0-9\/_| -]\/\", '_', $clean);\n  $clean = strtolower(trim($clean, '-'));\n  $clean = preg_replace(\"\/[\/_| -]+\/\", '_', $clean);\n\n  return $clean;\n} \/\/function<\/pre>\n<p>thanks to: sales at mk2solutions dot com for posting their solution @http:\/\/us2.php.net\/strtr notes<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need a good function to clean strings to use them as URLs for SEO purposes, here&#8217;s a suggestion: function chunk_special_chars($string)\u00a0{ $normalizeChars = array( &#8216;\u0160&#8217;=&gt;&#8217;S&#8217;, &#8216;\u0161&#8217;=&gt;&#8217;s&#8217;, &#8216;\u00d0&#8217;=&gt;&#8217;Dj&#8217;,&#8217;\u017d&#8217;=&gt;&#8217;Z&#8217;, &#8216;\u017e&#8217;=&gt;&#8217;z&#8217;, &#8216;\u00c0&#8217;=&gt;&#8217;A&#8217;, &#8216;\u00c1&#8217;=&gt;&#8217;A&#8217;, &#8216;\u00c2&#8217;=&gt;&#8217;A&#8217;, &#8216;\u00c3&#8217;=&gt;&#8217;A&#8217;, &#8216;\u00c4&#8217;=&gt;&#8217;A&#8217;, &#8216;\u00c5&#8217;=&gt;&#8217;A&#8217;, &#8216;\u00c6&#8217;=&gt;&#8217;A&#8217;, &#8216;\u00c7&#8217;=&gt;&#8217;C&#8217;, &#8216;\u00c8&#8217;=&gt;&#8217;E&#8217;, &#8216;\u00c9&#8217;=&gt;&#8217;E&#8217;, &#8216;\u00ca&#8217;=&gt;&#8217;E&#8217;, &#8216;\u00cb&#8217;=&gt;&#8217;E&#8217;, &#8216;\u00cc&#8217;=&gt;&#8217;I&#8217;, &#8216;\u00cd&#8217;=&gt;&#8217;I&#8217;, &#8216;\u00ce&#8217;=&gt;&#8217;I&#8217;, &#8216;\u00cf&#8217;=&gt;&#8217;I&#8217;, &#8216;\u00d1&#8217;=&gt;&#8217;N&#8217;, &#8216;\u00d2&#8217;=&gt;&#8217;O&#8217;, &#8216;\u00d3&#8217;=&gt;&#8217;O&#8217;, &#8216;\u00d4&#8217;=&gt;&#8217;O&#8217;, &#8216;\u00d5&#8217;=&gt;&#8217;O&#8217;,&#8230; <a class=\"continue-reading-link\" href=\"https:\/\/blog.portnumber53.com\/index.php\/2010\/10\/06\/php-function-to-clean-string-for-seo-usage-2\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[75,151,216,303],"class_list":["post-355","post","type-post","status-publish","format-standard","hentry","category-php","tag-clean-urls","tag-function","tag-library","tag-seo"],"_links":{"self":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/comments?post=355"}],"version-history":[{"count":0,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/posts\/355\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/media?parent=355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/categories?post=355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.portnumber53.com\/index.php\/wp-json\/wp\/v2\/tags?post=355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}