1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hubzilla_ynh.git synced 2024-09-03 19:26:21 +02:00
hubzilla_ynh/sources/library/urlify
2015-08-23 16:38:18 -04:00
..
tests Re-importing Hubzilla core and addons source 2015-08-23 16:38:18 -04:00
.gitignore Re-importing Hubzilla core and addons source 2015-08-23 16:38:18 -04:00
composer.json Re-importing Hubzilla core and addons source 2015-08-23 16:38:18 -04:00
INSTALL Re-importing Hubzilla core and addons source 2015-08-23 16:38:18 -04:00
README.md Re-importing Hubzilla core and addons source 2015-08-23 16:38:18 -04:00
URLify.php Re-importing Hubzilla core and addons source 2015-08-23 16:38:18 -04:00

URLify for PHP

A PHP port of URLify.js from the Django project. Handles symbols from Latin languages, Greek, Turkish, Russian, Ukrainian, Czech, Polish, and Latvian. Symbols it cannot transliterate it will simply omit.

Usage:

To generate slugs for URLs:

<?php

echo URLify::filter (' J\'étudie le français ');
// "jetudie-le-francais"

echo URLify::filter ('Lo siento, no hablo español.');
// "lo-siento-no-hablo-espanol"

?>

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 (array (
	'¿' => '?', '®' => '(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 (array ('remove', 'these', 'too'));

?>