DEV Community

Teddy Zugana
Teddy Zugana

Posted on • Edited on

2 1

PHP seo_friendly_url Example For Slugger

function seo_friendly_url($string){
$string = str_replace(array(‘[\’, \’]’), ”, $string);
$string = preg_replace(‘/[.*]/U’, ”, $string);
$string = preg_replace(‘/&(amp;)?#?[a-z0-9]+;/i’, ‘-‘, $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’, ‘/[-]+/’) , ‘-‘, $string);
return strtolower(trim($string, ‘-‘));
}rim($string, ‘-‘));
}

Top comments (2)

Collapse
 
bskiefer profile image
bskiefer
function seo_friendly_url($string){
    $string = str_replace(array(‘[\’, \’]’), ”, $string);
    $string = preg_replace(‘/[.*]/U’, ”, $string);
    $string = preg_replace(‘/&(amp;)?#?[a-z0-9]+;/i’, ‘-‘, $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’, ‘/[-]+/’) , ‘-‘, $string);
    return strtolower(trim($string, ‘-‘));
}
Collapse
 
vlasales profile image
Vlastimil Pospichal

Use tripple "`" for enclosure source code.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more