Created
December 16, 2016 07:04
-
-
Save fanatikhamsi/2fa514cf18151063aadcddfc4c7b0913 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Create URL Title | |
* | |
* Takes a "title" string as input and creates a | |
* human-friendly URL string with a "separator" string | |
* as the word separator. | |
* | |
* @access public | |
* @param string the string | |
* @param string the separator | |
* @return string | |
*/ | |
if ( ! function_exists('url_title')) | |
{ | |
function url_title($str, $separator = '-', $lowercase = TRUE) | |
{ | |
if ($separator == 'dash') | |
{ | |
$separator = '-'; | |
} | |
else if ($separator == 'underscore') | |
{ | |
$separator = '_'; | |
} | |
$q_separator = preg_quote($separator); | |
$trans = array( | |
'&.+?;' => '', | |
'[^a-z0-9 _-]' => '', | |
'\s+' => $separator, | |
'(' . $q_separator . ')+' => $separator | |
); | |
$search_tr = array('ı', 'İ', 'Ğ', 'ğ', 'Ü', 'ü', 'Ş', 'ş', 'Ö', 'ö', 'Ç', 'ç'); | |
$replace_tr = array('i', 'I', 'G', 'g', 'U', 'u', 'S', 's', 'O', 'o', 'C', 'c'); | |
$str = str_replace($search_tr, $replace_tr, $str); | |
$str = strip_tags($str); | |
foreach ($trans as $key => $val) | |
{ | |
$str = preg_replace("#".$key."#i", $val, $str); | |
} | |
if ($lowercase === TRUE) | |
{ | |
$str = strtolower($str); | |
} | |
return trim($str, $separator); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment