Hindi language words are available on the internet. You can use all Hindi words with the PHP preg_replace() function. I know you want to convert the Hindi title to slug using the Hindi language. If you want to learn that how to create SLUG in the Hindi language then you should follow the points below.
How to convert Hindi Title to Slug using PHP?
1. First of all, store your Hindi title into a variable.
2. Now, remove the beginning and last spaces from the string using the PHP trim() function. It removes unwanted spaces from the Hindi title.
3. We can use English words with a Hindi title. In this step, you have to convert the string to lower Use strtolower() function to convert lower.
4. Use Hindi language words in PHP preg_replace() function with numbers (0-9) , English characters (a-z), and Hindi words -
(_ोौेैा्ीिीूुंःअआइईउऊएऐओऔकखगघचछजझञटठडढतथदधनपफबभमयरलवसशषहश्रक्षटठडढङणनऋड़ )
This is the main part of the Hindi slug. It removes unwanted special characters and only adds matched Hindi and English words.
5. Add minus - separator between words
<?php
function slug($string)
{
$string = trim($string);$string=strtolower($string);
$string =preg_replace("/[^a-z0-9_ोौेैा्ीिीूुंःअआइईउऊएऐओऔकखगघचछजझञटठडढतथदधनपफबभमयरलवसशषहश्रक्षटठडढङणनऋड़\s-]/u", "", $string);
$string = preg_replace("/[\s-]+/", " ", $string);
$string = preg_replace("/[\s]/", '-', $string);
return $string ;
}
$title="हिंदी टाइटल का slug php के द्वारा कैसे बनाये। ";
echo slug($title)
?>
Output -
हिंदी-टाइटल-का-slug-php-के-द्वारा-कैसे-बनाये
Slug function is ready for Hindi and English words. If you want Hindi words only then remove a-z from PHP preg_replace()
Example -
$string =preg_replace("/[^0-9_ोौेैा्ीिीूुंःअआइईउऊएऐओऔकखगघचछजझञटठडढतथदधनपफबभमयरलवसशषहश्रक्षटठडढङणनऋड़\s-]/u", "", $string);
Output -
हिंदी-टाइटल-का-के-द्वारा-कैसे-बनाये
It will produce only Hindi slug.