regex - create URL slugs for chinese characters. Using PHP -
my users use chinese characters title of input.
my slugs in format of /stories/:id-:name
example /stories/1-i-love-php
.
how allow chinese characters?
i have googled , found japanese version of answer on here.
don't quite understand japanese, asking chinese version.
thank you.
i have tested in bengali characters
it may work. try this: @ first coded page (write code in page) have convert encoding type in utf-8, 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)
Comments
Post a Comment