create URL slugs for chinese characters. Using PHP

假如想象 提交于 2019-12-03 08:51:09

i have tested in Bengali characters

it may work. try this: at first the coded page (write code where in the page) have to convert into encoding type in UTF-8, then write code.

code here:

function to_slug($string, $separator = '-') {
    $re = "/(\\s|\\".$separator.")+/mu";
    $str = @trim($string);
    $subst = $separator;
    $result = preg_replace($re, $subst, $str);
    return $result;
}

$id=34;
$string_text="আড়াইহাজারে দেড় বছরের ---  শিশুর -গলায় ছুরি";
$base_url="http://example.com/";
echo $target_url=$base_url.$id."-". @to_slug($string_text);

var_dump($target_url);

output:

http://example.com/34-আড়াইহাজারে-দেড়-বছরের-শিশুর-গলায়-ছুরি

string 'http://example.com/34-আড়াইহাজারে-দেড়-বছরের-শিশুর-গলায়-ছুরি' (length=136)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!