为URL安全设置标题别名


Put title alias for URL safe

我尝试URL安全与以下功能,但它不适合阿拉伯语。怎样才能修好它?

DEMO Here

<?php
    function stringURLSafe($string)
{
    // remove any '-' from the string since they will be used as concatenaters
    $str = str_replace('-', ' ', $string);

    // Trim white spaces at beginning and end of alias and make lowercase
    $str = trim(strtolower($str));
    // Remove any duplicate whitespace, and ensure all characters are alphanumeric
    $str = preg_replace('/('s|[^A-Za-z0-9'-])+/', '-', $str);
    // Trim dashes at beginning and end of alias
    $str = trim($str, '-');
    return $str;
}
echo stringURLSafe('موقع إخباري: مرتبط بقناة {العربية} يقدم (على) مدار');

我希望在输出中:

موقع-إخباري-مرتبط-بقناة-العربية-يقدم-على-مدار

把你的正则表达式改成这个:
$str = preg_replace('/('s|[^'p{Arabic}'w0-9'-])+/u', '-', $str);
结果:
موقع——إخبار——ميرتبط——بقناة——العربية——يقدم——على——مدار