Description
A PHP port of URLify.js from the Django project. Handles symbols from Latin languages as well as Arabic, Azerbaijani, Czech, German, Greek, Latvian, Lithuanian, Polish, Romanian, Bulgarian, Russian, Serbian, Turkish, Ukrainian and Vietnamese. Symbols it cannot transliterate it will simply omit.
URLify alternatives and similar libraries
Based on the "Strings" category.
Alternatively, view URLify alternatives based on common mentions on social networks and blogs.
-
Mobile-Detect
Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment. -
UUID
:snowflake: A PHP library for generating universally unique identifiers (UUIDs). -
Agent
👮 A PHP desktop/mobile user agent parser with support for Laravel, based on Mobiledetect -
SQL Formatter
A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting. -
Device Detector
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model. -
Slugify
Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte. -
Jieba-PHP
"結巴"中文分詞:做最好的 PHP 中文分詞、中文斷詞組件。 / "Jieba" (Chinese for "to stutter") Chinese text segmentation: built to be the best PHP Chinese word segmentation module. -
Portable UTF-8
🉑 Portable UTF-8 library - performance optimized (unicode) string functions for PHP. -
Portable ASCII
🔡 Portable ASCII library - performance optimized (ascii) string functions for PHP. -
Color Jizz
ColorJizz is a PHP library for manipulating and converting colors. -
Google Translate For Free
Library for free use Google Translator. With attempts connecting on failure and array support. -
Case converter
Convert strings between 13 naming conventions: Snake case, Camel case, Kebab case, Pascal case, Ada case, Train case, Cobol case, Macro case, Upper case, Lower case, Title case, Sentence case and Dot notation. -
HaikunatorPHP
Generate Heroku-like random names to use in your php applications. -
Patchwork UTF-8
Extensive, portable and performant handling of UTF-8 and grapheme clusters for PHP -
Russian metaphone phonetic algorithm implementation for PHP
Russian metaphone algorithm implementation
Tired of breaking your main and manually rebasing outdated pull requests?
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of URLify or a related project?
README
URLify for PHP
A fast PHP slug generator and transliteration library, started as a PHP port of URLify.js from the Django project.
Handles symbols from latin languages, Arabic, Azerbaijani, Bulgarian, Burmese, Croatian, Czech, Danish, Esperanto,
Estonian, Finnish, French, Switzerland (French), Austrian (French), Georgian, German, Switzerland (German),
Austrian (German), Greek, Hindi, Kazakh, Latvian, Lithuanian, Norwegian, Persian, Polish, Romanian, Russian, Swedish,
Serbian, Slovak, Turkish, Ukrainian and Vietnamese, and many other via ASCII::to_transliterate()
.
Symbols it cannot transliterate it can omit or replace with a specified character.
Installation
Install the latest version with:
$ composer require jbroadway/urlify
Usage
First, include Composer's autoloader:
require_once 'vendor/autoload.php';
To generate slugs for URLs:
<?php
echo URLify::slug (' J\'étudie le français ');
// "jetudie-le-francais"
echo URLify::slug ('Lo siento, no hablo español.');
// "lo-siento-no-hablo-espanol"
To generate slugs for file names:
<?php
echo URLify::filter ('фото.jpg', 60, "", true);
// "foto.jpg"
To simply transliterate characters:
<?php
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:
<?php
URLify::add_chars ([
'¿' => '?', '®' => '(r)', '¼' => '1/4',
'½' => '1/2', '¾' => '3/4', '¶' => 'P'
]);
echo URLify::downcode ('¿ ® ¼ ¼ ¾ ¶');
// "? (r) 1/2 1/2 3/4 P"
To extend the list of words to remove:
<?php
URLify::remove_words (['remove', 'these', 'too']);
To prioritize a certain language map:
<?php
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.
*Note that all licence references and agreements mentioned in the URLify README section above
are relevant to that project's source code only.