DEV Community

Teddy Zugana
Teddy Zugana

Posted on • Edited on

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 (3)

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
 
mindmagic profile image
Mindmagic

Great guide! 🎨 I love how you broke down using Material Theme Builder with Stylify CSS — the step-by-step on generating the theme, exporting to CSS, and integrating with Stylify makes it super approachable. The examples with $md-sys-color-primary and dynamic display classes really help visualize how to apply Material Design in a utility-first workflow.

It’s especially helpful that you included tips for reducing HTTP requests and optimizing imports. Stylify seems like a powerful tool for anyone moving from CSS-in-JS to atomic CSS while keeping Material Design consistency.

Thanks for sharing this detailed walkthrough — looking forward to trying it in my next React project!

Collapse
 
vlasales profile image
Vlastimil Pospichal

Use tripple "`" for enclosure source code.