PHP Classes
elePHPant
Icontem

PHP URLify: Transliterate non-ASCII characters

Recommend this page to a friend!
  Info   View files Documentation   View files View files (56)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-12-01 (11 days ago) RSS 2.0 feedNot enough user ratingsTotal: 124 This week: 1All time: 8,664 This week: 556Up
Version License PHP version Categories
urlify 2.2.4BSD License5.3PHP 5, Text processing, SEO
Description Author

This class can transliterate non-ASCII characters.

It is a PHP port of URLify.js from the Django project.

It can take a text string encoded as UTF-8 and converts non-ascii characters like those with accents and cedillas and replaces them by equivalent ASCII versions. It also replaces spaces by dashes.

  Performance   Level  
Name: Lars Moelleken <contact>
Classes: 17 packages by
Country: Germany Germany
Age: 30
All time rank: 133584 in Germany Germany
Week rank: 7 Up1 in Germany Germany Up
Innovation award
Innovation award
Nominee: 8x

Details

Build Status Coverage Status codecov.io Scrutinizer Code Quality SensioLabsInsight Dependency Status Latest Stable Version Total Downloads Latest Unstable Version PHP 7 ready License

URLify for PHP

A PHP port of URLify.js from the Django project + str_transliterate from "Portable UTF-8".

  • https://github.com/django/django/blob/master/django/contrib/admin/static/admin/js/urlify.js
  • https://github.com/voku/portable-utf8

Handles symbols from many languages via an matching-array and others via "str_transliterate".

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/2 3/4 P"

To extend or replace the default replacing list:

URLify::add_array_to_seperator(array(
  "/®/"
));

echo URLify::filter('¿ ® ¼ ¼ ¾ ¶');
// "14-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'
  • Latvian: 'lv'
  • Lithuanian: 'lt'
  • Norwegian: 'no'
  • Polish: 'pl'
  • Romanian: 'ro'
  • Russian: 'ru'
  • Serbian: 'sr'
  • Swedish: 'sv'
  • Switzerland (German): 'de_ch'
  • Switzerland (French): 'fr_ch'
  • Turkish: 'tr'
  • Ukrainian: 'uk'
  • Vietnamese: 'vn'
  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Files folder imagetests (9 files, 1 directory)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file INSTALL Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imagevoku (1 directory)

  Files folder image Files  /  src  /  voku  
File Role Description
Files folder imagehelper (1 file)

  Files folder image Files  /  src  /  voku  /  helper  
File Role Description
  Plain text file URLify.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imagefixtures (1 directory)
  Plain text file BaseSluggerTest.php Class Class source
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Accessible without login Plain text file profile.php Aux. Auxiliary script
  Plain text file SeoSluggerTest.php Class Class source
  Plain text file SeoUtf8SluggerTest.php Class Class source
  Plain text file SluggerTest.php Class Class source
  Plain text file URLifyTest.php Class Class source
  Plain text file Utf8SluggerTest.php Class Class source
  Plain text file Utf8UrlSlugTest.php Class Class source

  Files folder image Files  /  tests  /  fixtures  
File Role Description
Files folder imageurlify (2 directories)

  Files folder image Files  /  tests  /  fixtures  /  urlify  
File Role Description
Files folder imageexpected (18 files)
Files folder imageinput (18 files)

  Files folder image Files  /  tests  /  fixtures  /  urlify  /  expected  
File Role Description
  Accessible without login Plain text file arabic.txt Doc. Documentation
  Accessible without login Plain text file hebrew.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-1-1.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-1.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-2-1.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-2.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-3-1.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-3.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-4-1.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-4.txt Doc. Documentation
  Accessible without login Plain text file japanese.txt Doc. Documentation
  Accessible without login Plain text file pangrams-1.txt Doc. Documentation
  Accessible without login Plain text file pangrams.txt Doc. Documentation
  Accessible without login Plain text file sample-unicode-chart.txt Doc. Documentation
  Accessible without login Plain text file sample-utf-8-bom.txt Doc. Documentation
  Accessible without login Plain text file strings-1.txt Doc. Documentation
  Accessible without login Plain text file strings-2.txt Doc. Documentation
  Accessible without login Plain text file strings-3.txt Doc. Documentation

  Files folder image Files  /  tests  /  fixtures  /  urlify  /  input  
File Role Description
  Accessible without login Plain text file arabic.txt Doc. Documentation
  Accessible without login Plain text file hebrew.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-1-1.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-1.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-2-1.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-2.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-3-1.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-3.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-4-1.txt Doc. Documentation
  Accessible without login Plain text file iso-8859-4.txt Doc. Documentation
  Accessible without login Plain text file japanese.txt Doc. Documentation
  Accessible without login Plain text file pangrams-1.txt Doc. Documentation
  Accessible without login Plain text file pangrams.txt Doc. Documentation
  Accessible without login Plain text file sample-unicode-chart.txt Doc. Documentation
  Accessible without login Plain text file sample-utf-8-bom.txt Doc. Documentation
  Accessible without login Plain text file strings-1.txt Doc. Documentation
  Accessible without login Plain text file strings-2.txt Doc. Documentation
  Accessible without login Plain text file strings-3.txt Doc. Documentation

Downloadurlify-2017-12-01.zip 66KB
Downloadurlify-2017-12-01.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Portable UTF-8 Download .zip .tar.gz toASCII() is needed Required
 Version Control Unique User Downloads Download Rankings  
 100%
Total:124
This week:1
All time:8,664
This week:556Up