使所有小写,并将空格替换为-


Make all lower case and replace spaces with -

我正在尝试生成一些html页面,我有:

$category="Category Name";
$zone="Zone Name";

我正在尝试获取$page="category-name-in-zone-name.html"

您正在寻找"段塞创建"的概念:

function makeSlug($input)
{
    $interim = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $input);
    $interim = preg_replace("/['"']+/i", '', $interim);
    $interim = preg_replace("/[^a-z0-9''d]+/i", '-', $interim);
    return trim(strtolower($interim), ' -');
}
echo makeSlug("$category in $zone").'.html';

在这里演示。