3
PHP Create slugify URL from All language to English
source link: https://dev.to/aradpardaz/php-create-slugify-url-from-all-language-to-english-229g
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
PHP transliterator_transliterate - examples . These are the top rated real world PHP examples of transliterator_transliterate extracted from open source projects. You can rate examples to help us improve the quality of examples.
Programming Language: PHP
Method/Function: transliterator_transliterate
(PHP 5 >= 5.4.0, PHP 7, PECL intl >= 2.0.0)
📝Description
public Transliterator::transliterate ( string $subject [, int $start [, int $end ]] ) : string|false
Enter fullscreen modeExit fullscreen mode
📝Parameters
transliterator
In the procedural version, either a Transliterator or a string from which a Transliterator can be built.
Enter fullscreen modeExit fullscreen mode
subject
The string to be transformed.
Enter fullscreen modeExit fullscreen mode
start
The start index (in UTF-16 code units) from which the string will start to be transformed, inclusive. Indexing starts at 0. The text before will be left as is.
Enter fullscreen modeExit fullscreen mode
The end index (in UTF-16 code units) until which the string will be transformed, exclusive. Indexing starts at 0. The text after will be left as is.
Enter fullscreen modeExit fullscreen mode
Code Example 1:
<?php
function slugify($string)
{
$string = transliterator_transliterate("Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove; Lower();", $string);
$string = preg_replace('/[-\s]+/', '-', $string);
return trim($string, '-');
}
echo '/n'.slugify('A æ Übérmensch på høyeste nivå! И я люблю PHP! fi');
//out: a-ae-ubermensch-pa-hoyeste-niva!-i-a-lublu-php!-fi
echo '/n'.slugify('وب فارسی در مجله دلگرم delgarm');
//out: wb-farsy-dr-mjlh-dlgrm-delgarm
echo '/n'.slugify('أصبح تسجيل طلاب الصف الأول إلكترونيًا');
//out: asbh-tsjyl-tlab-alsf-alawl-alktrwnyaa
?>
Enter fullscreen modeExit fullscreen mode
function Example 2:
public static function slugify($string, $separator = null)
{
$separator = null !== $separator ? $separator : (null !== self::$separator ? self::$separator : '-');
$slug = trim(strip_tags($string));
$slug = transliterator_transliterate('NFD; [:Nonspacing Mark:] Remove; NFC; Any-Latin; Latin-ASCII; Lower();', $slug);
$slug = preg_replace("/[^a-zA-Z0-9\\/_|+ -]/", '', $slug);
$slug = preg_replace("/[\\/_|+ -]+/", $separator, $slug);
$slug = trim($slug, $separator);
return $slug;
}
Enter fullscreen modeExit fullscreen mode
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK