stathisg / greek-slug-generator

一个支持希腊UTF-8编码字符的slug(美观URL)生成器

2.0.2 2017-05-29 12:54 UTC

This package is not auto-updated.

Last update: 2024-09-23 05:43:17 UTC


README

GreekSlugGenerator 是一个 slug(美观URL)生成器,支持希腊UTF-8编码字符,基于字符串(通常是页面或文章的标题)生成slug。

该类也可以用于仅包含英文标题。

如果发现希腊字符,则将其转换为英文等效字符。

空格以及一些标点符号被转换为破折号,但如果在某个地方产生多个连续的破折号,则最终的slug中只出现一个。

安装

可以通过在 src 目录下要求 GreekSlugGenerator.php 文件,或者通过Composer使用 Packagist存档 来安装。

示例

use \StathisG\GreekSlugGenerator\GreekSlugGenerator;

// produces: the-class-can-be-used-for-english-only-titles-as-well
echo GreekSlugGenerator::getSlug('The class can be used for ENGLISH-ONLY titles as well');

// produces: it-ignores-multiple-spaces-between-the-words
echo GreekSlugGenerator::getSlug('It   ignores   multiple   spaces   between   the   words');

// produces: as-well-as-brackets-quotes-commas-and-full-stops
echo GreekSlugGenerator::getSlug('As well as brackets {[()]}, quotes `\'", commas, and full stops.');

//produces: some-others-are-converted-in-dashes-but-if-at-any-point-multiple-sequential-dashes-are-produced-only-one-appears-
echo GreekSlugGenerator::getSlug('Some others are converted in dashes, but if at any point multiple sequential dashes are produced, only one appears: \/_-');

// produces: greek-example-1-ekthesh-fwtografias-to-rethymno-kai-h-thalassa-hmeres-rethymnoy-2013
echo GreekSlugGenerator::getSlug('Greek example #1: Έκθεση Φωτογραφίας «Το Ρέθυμνο και η Θάλασσα» - "Ημέρες Ρεθύμνου" 2013');

// produces: greek-example-2-h-ekthesh-ksekinaei-thn-tetarth-08-05-2013-kai-wra-20-45-h-diarkeia-ths-ektheshs-tha-einai-apo-08-05-ews-07-06
echo GreekSlugGenerator::getSlug('Greek example #2: Η έκθεση ξεκινάει την Τετάρτη 08/05/2013 και ώρα 20:45. Η διάρκεια της έκθεσης θα είναι από 08/05 έως 07/06');