I've written an answer for Hindi words to slug using PHP. You can use the same function to create your Arabic language slug in PHP. I've explained there -
How to convert the Arabic language Title to Slug in PHP?
1. First of all, save the Arabic title or you can say Arabic language string in a variable.
2. Now, remove the beginning and last spaces from the string using the PHP trim() function. It removes the first and last unwanted spaces from the Arabic language string.
3. We can use English words with an Arabic language title. In this step, you have to convert the string to lower Use strtolower() function to convert lower.
4. Use Arabic language words in PHP preg_replace() function with numbers (0-9) , English characters (a-z), and Arabic words -
ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى
This is the main part of the Arabic slug. It removes unwanted special characters and only adds matched Arabic and English words.
5. Add minus - separator between words.
<?php
function Arabic_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="كيفية تحويل الكلمات العربية إلى سبيكة في | PHP?";
echo Arabic_slug($title)
?>
Output -
كيفية-تحويل-الكلمات-العربية-إلى-سبيكة-في-php
The slug function is ready for Arabic and English words. If you want Arabic language words only then remove a-z from PHP preg_replace()
Example -
$string =preg_replace("/[^0-9_ءاأإآؤئبتثجحخدذرزسشصضطظعغفقكلمنهويةى\s-]/u", "", $string);
Output -
كيفية-تحويل-الكلمات-العربية-إلى-سبيكة-في
Use the Arabic_slug() function to convert Arabic language title to slug() .