If you're having trouble with URLs, I want you to be able to change topics that can contain anything and strip all special characters so they only have letters and numbers and then I'd like to add spaces with hyphens.


Here is a PHP function to make your URL SEO friendly URL just use a regular expression to clean your URL look at the following example to clean your URL as user friendly 


Sad Original URLsite.com/page.php?category=2&product=54
Happy URLsite.com/sandwiches/rueben-sandwich/

#example.php

  <?php
   
    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, '-'));
    }

    $str = " site.com/page.php?category=2&product=54";
    echo seo_friendly_url($str);
    ?>