// // Convert Text to 'Safe Url' // // Mark Jacksons Function function safeURL($txt,$allowSpace=false,$allowCaps=false) { $find = array('/à|á|â|ã|ä|å/', '/ç/', '/è|é|ê|ë/', '/ì|í|î|ï/', '/ñ/', '/ð|ó|ò|ô|õ|ö|ø/', '/ù|ú|û|ü/', '/ý|ÿ/'); $replace = array('a', 'c', 'e', 'i', 'n', 'o', 'u', 'y'); $txt = trim($txt); $txt = preg_replace($find,$replace,$txt); if(!$allowSpace) { $txt = str_replace(' ','-',$txt); } // remove all other unwanted characters if(!$allowCaps) { $txt = strtolower($txt); } $pattern = ($allowCaps) ? '/[^a-zA-Z0-9\s_\-]/' : '/[^a-z0-9\s_\-]/'; $txt = preg_replace($pattern,'',$txt); return $txt; }
This function was written by the mighty Mark Jackson
You use it like: $myvar = safeURL(‘Joe Blogs Bio Page’); which produces joe-blogs-bio-page
Main Category
Secondary Categories