urlify

PHP port of URLify.js from the Django project. Transliterates non-ascii characters for use in URLs.

Github星跟蹤圖

URLify for PHP Build Status

A PHP port of URLify.js
from the Django project. Handles symbols from Latin languages as well as Arabic, Azerbaijani, Czech, German, Greek, Kazakh,
Latvian, Lithuanian, Persian, Polish, Romanian, Bulgarian, Russian, Serbian, Turkish, Ukrainian, Vietnamese and Slovak. Symbols it cannot
transliterate it will simply omit.

Installation

Install the latest version with:

$ composer require jbroadway/urlify

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 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.

主要指標

概覽
名稱與所有者jbroadway/urlify
主編程語言PHP
編程語言PHP (語言數: 1)
平台
許可證BSD 3-Clause "New" or "Revised" License
所有者活动
創建於2012-05-01 22:28:56
推送於2025-04-03 17:52:34
最后一次提交2025-04-02 04:08:37
發布數20
最新版本名稱1.2.5-stable (發布於 )
第一版名稱1.0.0-stable (發布於 )
用户参与
星數676
關注者數34
派生數79
提交數157
已啟用問題?
問題數20
打開的問題數6
拉請求數47
打開的拉請求數0
關閉的拉請求數6
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?