Created
December 7, 2017 17:32
-
-
Save gbutiri/f3c71b8938918fc965a00211a5d41565 to your computer and use it in GitHub Desktop.
CodeIgniter Helper - Friendly URL
This file contains hidden or 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 | |
function friendlyURL($string, $is_file = false, $delimiter = '-'){ | |
if ($is_file) { | |
$name = pathinfo($string, PATHINFO_FILENAME); | |
$ext = pathinfo($string, PATHINFO_EXTENSION); | |
$filename = friendlyUrl($name) . '.' . friendlyUrl($ext); | |
return $filename; | |
} else { | |
$string = preg_replace("`\[.*\]`U","",$string); | |
$string = preg_replace('`&(amp;)?#?[a-z0-9]+;`i', $delimiter, $string); | |
$string = htmlentities($string, ENT_COMPAT, 'utf-8'); | |
$string = preg_replace( "`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i","\\1", $string ); | |
$string = preg_replace( array("`[^a-z0-9]`i","`[-]+`") , $delimiter, $string); | |
} | |
return strtolower(trim($string)); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment