voku/urlify
PHP URL slugifier/transliterator (URLify.js port) that converts UTF-8 strings into readable, URL-safe slugs and filenames. Supports many languages via mapping tables with Portable ASCII fallback, plus helpers like downcode/transliterate and custom char rules.
Convert any string into an valid and readable string for usage in the url.
This is a PHP port of "URLify.js" from the Django project + fallback via "Portable ASCII". We handles symbols from many languages via an matching-array and others via "ASCII::to_transliterate()".
composer require voku/urlify
namespace: "voku\helper\URLify"
echo URLify::filter(' J\'étudie le français ');
// "J-etudie-le-francais"
echo URLify::filter('Lo siento, no hablo español.');
// "Lo-siento-no-hablo-espanol"
echo URLify::filter('фото.jpg', 60, '', true);
// "foto.jpg"
echo URLify::downcode('J\'étudie le français');
// "J'etudie le francais"
echo URLify::downcode('Lo siento, no hablo español.');
// "Lo siento, no hablo espanol."
/* Or use transliterate() alias: */
echo URLify::transliterate('Lo siento, no hablo español.');
// "Lo siento, no hablo espanol."
URLify::add_chars(array(
'¿' => '?', '®' => '(r)', '¼' => '1/4',
'½' => '1/2', '¾' => '3/4', '¶' => 'P'
));
echo URLify::downcode('¿ ® ½ ¼ ¾ ¶');
// "? (r) 1/2 1/4 3/4 P"
URLify::add_array_to_seperator(array(
"/®/"
));
echo URLify::filter('¿ ® ½ ¼ ¾ ¶');
// "12-14-34-P"
URLify::remove_words(array('remove', 'these', 'too'), 'de');
echo URLify::filter(' Ägypten und Österreich besitzen wie üblich ein Übermaß an ähnlich öligen Attachés ', 60, 'de');
// "Aegypten-und-Oesterreich-besitzen-wie-ueblich-ein-Uebermass-aehnlich-oeligen-Attaches"
echo URLify::filter('Cağaloğlu, çalıştığı, müjde, lazım, mahkûm', 60, 'tr');
// "Cagaloglu-calistigi-mujde-lazim-mahkum"
Please note that the "ü" is transliterated to "ue" in the first case, whereas it results in a simple "u" in the latter.
For support and donations please visit Github | Issues | PayPal | Patreon.
For status updates and release announcements please visit Releases | Twitter | Patreon.
For professional support please contact me.
How can I help you explore Laravel packages today?