Create Clean\Pretty URLs in PHP

PHP function to clean an URL in PHP:

function PhpCleanURL($string)
{
    return strtolower(trim(preg_replace('/[^a-zA-Z0-9]+/', '-', trim($string)), '-'));
}

Example usage:

echo "Clean URL: ".PhpCleanURL("Post Title with @ Special ChArS");

Example output:

Clean URL: post-title-with-special-chars

More Related Posts