Php 放置URL安全的标题别名

Php 放置URL安全的标题别名,php,regex,Php,Regex,我尝试使用下面的URL安全功能,但它不适用于阿拉伯语。怎么能修好呢 <?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 en

我尝试使用下面的URL安全功能,但它不适用于阿拉伯语。怎么能修好呢

<?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('موقع إخباري: مرتبط بقناة {العربية} يقدم (على) مدار');

将您的regexp更改为此:
$str=preg_replace('/(\s|[^\p{Arabic}\w0-9\-])+/u','-',$str)
结果如下:

这是一个无效的URL。您必须
urlencode()
字符串。
موقع-إخباري-مرتبط-بقناة-العربية-يقدم-على-مدار