Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to strip unwanted characters from title to make a URL-only title?
Hello all,
My article is not in English so with the default engine to create URL-only title. Some must-have characters are striped. So I would like how to manage this hook. For example:
function deLocalize($inStr)
{
$outStr = $inStr;
$outStr = preg_replace('@[éÉèÈẻẺẽẼẹẸêÊếẾềỀểỂễỄệỆ]@u', 'e', $outStr);
$outStr = preg_replace('@[úÚùÙủỦũŨụỤưƯứỨừỪửỬữỮựỰ]@u', 'u', $outStr);
$outStr = preg_replace('@[íÍìÌỉỈĩĨịỊ]@u', 'i', $outStr);
$outStr = preg_replace('@[óÓòÒỏỎõÕọỌôÔơƠốỐồỒổỔỗỖộỘớỚờỜởỞỡỠợỢ]@u', 'o', $outStr);
$outStr = preg_replace('@[áÁàÀảẢãÃạẠâÂăĂấẤầẦẩẨẫẪậẬắẮằẰẳẲẵẴặẶ]@u', 'a', $outStr);
$outStr = preg_replace('@[đĐ]@u', 'd', $outStr);
return $outStr;
}
Thanks & regards,
Last edited by HAC (2011-11-08 05:07:34)
Offline
Re: How to strip unwanted characters from title to make a URL-only title?
If you just want to get the article-url title of an article, use txp:article_url_title.
If you want to convert your own text to the same kind of format, there’s an in-built function for that in txp called sanitizeforurl.
Together with rah_function you can use it as follows:
<txp:rah_function call="sanitizeforurl">Your text to convert</txp:rah_function>
TXP Builders – finely-crafted code, design and txp
Offline