Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-11-08 05:05:16

HAC
Member
From: Vietnam
Registered: 2009-06-05
Posts: 33
Website

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

#2 2011-11-08 08:51:22

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

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

Board footer

Powered by FluxBB