{"id":18,"date":"2013-05-03T16:49:04","date_gmt":"2013-05-03T10:49:04","guid":{"rendered":"http:\/\/ronniee.net\/?p=18"},"modified":"2013-06-07T12:08:10","modified_gmt":"2013-06-07T06:08:10","slug":"php-function-to-make-string-url-safe","status":"publish","type":"post","link":"https:\/\/ronniee.net\/?p=18","title":{"rendered":"Php function to make string URL safe"},"content":{"rendered":"<pre class=\"lang:php decode:true crayon-selected\">&lt;?php \r\n\/**\r\n* This method processes a string and replaces all accented UTF-8 characters by unaccented\r\n* ASCII-7 \"equivalents\", whitespaces are replaced by hyphens and the string is lowercase.\r\n*\/\r\nfunction stringURLSafe($string)\r\n{\r\n\r\n      \/\/ Remove any '-' from the string since they will be used as concatenaters\r\n      $str = str_replace('-', ' ', $string);\r\n\r\n      \/\/ Trim white spaces at beginning and end of alias and make lowercase\r\n      $str = trim(strtolower($str));\r\n\r\n      \/\/ Remove any duplicate whitespace, and ensure all characters are alphanumeric\r\n      $str = preg_replace('\/(\\s|[^A-Za-z0-9\\-])+\/', '-', $str);\r\n\r\n      \/\/ Trim dashes at beginning and end of alias\r\n      $str = trim($str, '-');\r\n\r\n      return $str;\r\n}\r\n\r\n?&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php \/** * This method processes a string and replaces all accented UTF-8 characters by unaccented * ASCII-7 &#8220;equivalents&#8221;, whitespaces are replaced by hyphens and the string is lowercase. *\/ function stringURLSafe($string) { \/\/ Remove any &#8216;-&#8216; from the string since they will be used as concatenaters $str = str_replace(&#8216;-&#8216;, &#8216; &#8216;, $string); \/\/ Trim [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ronniee.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=18"}],"version-history":[{"count":13,"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":20,"href":"https:\/\/ronniee.net\/index.php?rest_route=\/wp\/v2\/posts\/18\/revisions\/20"}],"wp:attachment":[{"href":"https:\/\/ronniee.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ronniee.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ronniee.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}