voku / urlify
PHP port of URLify.js from the Django project. Transliterates non-ascii characters for use in URLs.
Fund package maintenance!
voku
Patreon
Tidelift
www.paypal.me/moelleken
Installs: 3 434 620
Dependents: 8
Suggesters: 0
Security: 0
Stars: 25
Watchers: 4
Forks: 79
Open Issues: 2
Requires
- php: >=7.0.0
- voku/portable-ascii: ~2.0
- voku/portable-utf8: ~6.0
- voku/stop-words: ~2.0
Requires (Dev)
- phpunit/phpunit: ~6.0 || ~7.0 || ~9.0
- dev-master
- 5.0.7
- 5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.1.1
- 4.1.0
- 4.0.0
- 3.0.0
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5-stable
- 2.0.4-stable
- 2.0.3-stable
- 2.0.2-stable
- 2.0.1-stable
- 2.0.0-stable
- 1.3.0-stable
- 1.2.14-stable
- 1.2.13-stable
- 1.2.12-stable
- 1.2.11-stable
- 1.2.10-stable
- 1.2.9-stable
- 1.2.8-stable
- 1.2.7-stable
- 1.2.6-stable
- 1.2.5-stable
- 1.2.4-stable
- 1.2.3-stable
- 1.2.2-stable
- 1.2.1-stable
- 1.2.0-stable
- 1.1.3-stable
- 1.1.2-stable
- 1.1.1-stable
- 1.1.0-stable
- 1.0.10-stable
- 1.0.9-stable
- 1.0.8-stable
- 1.0.7-stable
- 1.0.6-stable
- 1.0.5-stable
- 1.0.4-stable
- 1.0.3-stable
- 1.0.2-stable
- 1.0.1-stable
- 1.0.0-stable
- dev-dependabot/add-v2-config-file
- dev-whitesource/configure
- dev-fork-updates
This package is auto-updated.
Last update: 2024-12-04 05:22:34 UTC
README
🔗 URLify
Description
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()".
- https://github.com/django/django/blob/master/django/contrib/admin/static/admin/js/urlify.js
- https://github.com/voku/portable-ascii
- https://github.com/voku/portable-utf8
Install via "composer require"
composer require voku/urlify
Usage:
namespace: "voku\helper\URLify"
To generate slugs for URLs:
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"
To generate slugs for file names:
echo URLify::filter('фото.jpg', 60, '', true); // "foto.jpg"
To simply transliterate characters:
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."
To extend the character list:
URLify::add_chars(array( '¿' => '?', '®' => '(r)', '¼' => '1/4', '½' => '1/2', '¾' => '3/4', '¶' => 'P' )); echo URLify::downcode('¿ ® ½ ¼ ¾ ¶'); // "? (r) 1/2 1/4 3/4 P"
To extend or replace the default replacing list:
URLify::add_array_to_seperator(array( "/®/" )); echo URLify::filter('¿ ® ½ ¼ ¾ ¶'); // "12-14-34-P"
To extend the list of words to remove for one language:
URLify::remove_words(array('remove', 'these', 'too'), 'de');
To prioritize a certain language map:
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.
Available languages
- Arabic: 'ar'
- Austrian (German): 'de_at'
- Austrian (French): 'fr_at'
- Azerbaijani: 'az'
- Bulgarian: 'bg'
- Burmese: 'by'
- Croatian: 'hr'
- Czech: 'cs'
- Danish: 'da'
- English: 'en'
- Esperanto: 'eo'
- Estonian: 'et'
- Finnish: 'fi'
- French: 'fr'
- Georgian: 'ka'
- German: 'de'
- Greek: 'el'
- Hindi: 'hi'
- Hungarian: 'hu'
- Kazakh: 'kk'
- Latvian: 'lv'
- Lithuanian: 'lt'
- Norwegian: 'no'
- Polish: 'pl'
- Romanian: 'ro'
- Russian: 'ru'
- Serbian: 'sr'
- Slovak: 'sk'
- Swedish: 'sv'
- Switzerland (German): 'de_ch'
- Switzerland (French): 'fr_ch'
- Turkish: 'tr'
- Ukrainian: 'uk'
- Vietnamese: 'vn'
Support
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.
Thanks
- Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
- Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
- Thanks to StyleCI for the simple but powerfull code style check.
- Thanks to PHPStan && Psalm for relly great Static analysis tools and for discover bugs in the code!