I am working in a laravel project. I have slugged url. Its working fine for English language. But while I use Bangla it returns empty. Please help me to solve the issue.
JavaScript
x
echo str_slug("hi there");
// Result: hi-there
echo str_slug("বাংলাদেশ ব্যাংকের রিজার্ভের অর্থ চুরির ঘটনায় ফিলিপাইনের");
// Result: '' (Empty)
Advertisement
Answer
str_slug
or facade version Str::slug
doesn’t work with non-ascii string. You can instead use this approach
JavaScript
function make_slug($string) {
return preg_replace('/s+/u', '-', trim($string));
}
$slug = make_slug(" বাংলাদেশ ব্যাংকের রিজার্ভের অর্থ চুরির ঘটনায় ফিলিপাইনের ");
echo $slug;
// Output: বাংলাদেশ-ব্যাংকের-রিজার্ভের-অর্থ-চুরির-ঘটনায়-ফিলিপাইনের