Wednesday, 3 June 2015

simple uri location

<?php /** 
* function simpleURI (string $text, boolean $low, boolean $html = false) 
* 
* Create a optimized url from a regular string 
* 
* @$low: true/false lowercase / normal case 
* @$html: true/false the function get an html string 
* @$utf8: true/false use UTF-8 or ISO-8859-1 
* 
* Example: 
* 
* $title = 'How old are you?, (question)'; 
* $simple = simpleURI($title); 
* $myurl = 'http://myweb.com/blog/'.$simple; 
* 
* return string 
*/ 
function simpleURI ($text$low true$html false$utf8 true) { 
    if (!
$html) { 
        
$text htmlentities($textENT_QUOTES$utf8?'UTF-8':'ISO-8859-1'); 
    } 

    
$text preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/i''$1'$text); 
    
$text html_entity_decode($textENT_QUOTES$utf8?'UTF-8':'ISO-8859-1'); 

    
$text preg_replace(array('/[^a-z0-9_-]/i''/-+/''/^-/''/-$/',), array('-''-'''''), $text); 

    return 
$low?strtolower($text):$text; 
} 
?>

0 comments:

Post a Comment