项目作者: jbroadway

项目描述 :
A fast PHP slug generator and transliteration library that converts non-ascii characters for use in URLs.
高级语言: PHP
项目地址: git://github.com/jbroadway/urlify.git
创建时间: 2012-05-01T22:28:56Z
项目社区:https://github.com/jbroadway/urlify

开源协议:Other

下载


URLify for PHP

GitHub Workflow Status (branch)
Packagist License
Packagist Version
Packagist PHP Version Support
Packagist Downloads

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:

  1. $ composer require jbroadway/urlify

Usage

First, include Composer’s autoloader:

  1. require_once 'vendor/autoload.php';

To generate slugs for URLs:

  1. <?php
  2. echo URLify::slug (' J\'étudie le français ');
  3. // "jetudie-le-francais"
  4. echo URLify::slug ('Lo siento, no hablo español.');
  5. // "lo-siento-no-hablo-espanol"

To generate slugs for file names:

  1. <?php
  2. echo URLify::filter ('фото.jpg', 60, "", true);
  3. // "foto.jpg"

To simply transliterate characters:

  1. <?php
  2. echo URLify::downcode ('J\'étudie le français');
  3. // "J'etudie le francais"
  4. echo URLify::downcode ('Lo siento, no hablo español.');
  5. // "Lo siento, no hablo espanol."
  6. /* Or use transliterate() alias: */
  7. echo URLify::transliterate ('Lo siento, no hablo español.');
  8. // "Lo siento, no hablo espanol."

To extend the character list:

  1. <?php
  2. URLify::add_chars ([
  3. '¿' => '?', '®' => '(r)', '¼' => '1/4',
  4. '½' => '1/2', '¾' => '3/4', '¶' => 'P'
  5. ]);
  6. echo URLify::downcode ('¿ ® ¼ ¼ ¾ ¶');
  7. // "? (r) 1/2 1/2 3/4 P"

To extend the list of words to remove:

  1. <?php
  2. URLify::remove_words (['remove', 'these', 'too']);

To prioritize a certain language map:

  1. <?php
  2. echo URLify::filter ('Ägypten und Österreich besitzen wie üblich ein Übermaß an ähnlich öligen Attachés', 60, 'de');
  3. // "aegypten-und-oesterreich-besitzen-wie-ueblich-ein-uebermass-aehnlich-oeligen-attaches"
  4. echo URLify::filter ('Cağaloğlu, çalıştığı, müjde, lazım, mahkûm', 60, 'tr');
  5. // "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.