Franz I have the code ready, but it's just a simple code. I'm not a php developer so the code will need be reviewed by PHP developers and correctly adapted to use in Flarum. All parts of the code are based on replacements posted at http://stackoverflow.com/questions/3371697/replacing-accented-characters-php/3373364 and exploring other sources.
A) The code supports unicode chars, this means that chinese, corean and other languages can be used.
B] The code has one limitation, some replacements are locale specif. While flarum core don't offer something to get the locale being used, these replacements are simply unavailable. Anyway the number of these replacements is low and affects only to:
- German - GERMANY (de_DE)
- Danish - DENMARK (da_DK)
- Serbian - SERBIA (sr_RS)
C) Into very rare situations, the returned string can be empty, for example if you use "@@@@@@" as title. This situations should be handled with a fallback_slug
that we can get for example generating a random string (to keep thigs simple).
D) At some parts of the code it uses mbstring
functions but... since it's a Flarum requirement, it shouldn't be an issue.
E) How can we review and test this code more in depth? is this possible?
To finish some examples:
Input:
$slug = 'Cómo *-*/`´Ç {} coño <php . « es % está & estò ÑoñoÁ ! o ¡ una \' @ y un # con   plaza 中文百强网';
echo create_slug($slug);
Output:
como-c-cono-php-es-esta-esto-nonoa-o-una-y-un-con-nbsp-plaza-%e4%b8%ad%e6%96%87%e7%99%be%e5%bc%ba%e7%bd%91
URL-decoded output:
como-c-cono-php-es-esta-esto-nonoa-o-una-y-un-con-nbsp-plaza-中文百强网
Input:
$slug = "@@_يسpo中文to한국관광공";
echo create_slug($slug);
Output:
_%d9%8a%d8%b3po%e4%b8%ad%e6%96%87to%ed%95%9c%ea%b5%ad%ea%b4%80%ea%b4%91%ea%b3%b5
URL-decoded output:
_يسpo中文to한국관광공
Maybe you can help me testing this @Aethior
Simply use this Str.php
and run tests (remember to clear flarum cache first):
https://gist.github.com/Zeokat/4ab3a0ecaeec6d6fadff66634edcb729