PHP Create slugify URL from All language to English

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 L…


This content originally appeared on DEV Community and was authored by Nima Sadeghi

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

?Parameters

transliterator

In the procedural version, either a Transliterator or a string from which a Transliterator can be built.

subject

The string to be transformed.

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.

end

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.

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

?>

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;
 }


This content originally appeared on DEV Community and was authored by Nima Sadeghi


Print Share Comment Cite Upload Translate Updates
APA

Nima Sadeghi | Sciencx (2021-07-23T19:40:49+00:00) PHP Create slugify URL from All language to English. Retrieved from https://www.scien.cx/2021/07/23/php-create-slugify-url-from-all-language-to-english/

MLA
" » PHP Create slugify URL from All language to English." Nima Sadeghi | Sciencx - Friday July 23, 2021, https://www.scien.cx/2021/07/23/php-create-slugify-url-from-all-language-to-english/
HARVARD
Nima Sadeghi | Sciencx Friday July 23, 2021 » PHP Create slugify URL from All language to English., viewed ,<https://www.scien.cx/2021/07/23/php-create-slugify-url-from-all-language-to-english/>
VANCOUVER
Nima Sadeghi | Sciencx - » PHP Create slugify URL from All language to English. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/23/php-create-slugify-url-from-all-language-to-english/
CHICAGO
" » PHP Create slugify URL from All language to English." Nima Sadeghi | Sciencx - Accessed . https://www.scien.cx/2021/07/23/php-create-slugify-url-from-all-language-to-english/
IEEE
" » PHP Create slugify URL from All language to English." Nima Sadeghi | Sciencx [Online]. Available: https://www.scien.cx/2021/07/23/php-create-slugify-url-from-all-language-to-english/. [Accessed: ]
rf:citation
» PHP Create slugify URL from All language to English | Nima Sadeghi | Sciencx | https://www.scien.cx/2021/07/23/php-create-slugify-url-from-all-language-to-english/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.