Pitu
Pitu

Reputation: 159

Smarty PHP remove specific text from a string

I have a string:

ćśóławegfdfsd

This string is with a polish char.

I want change this in smart on

csolawegfdfsd

In Smarty only.

Upvotes: 2

Views: 1213

Answers (2)

cmbuckley
cmbuckley

Reputation: 42458

How about registering the following plugin:

$smarty->registerPlugin('modifier', 'translit', 'print_translit');

function print_translit($string) {
    return iconv('UTF-8', 'ASCII//TRANSLIT', $string);
}

Usage:

{$var|translit}

This will transliterate the Polish characters. You may also want to append //IGNORE to the output format to ignore characters which can't be transliterated.

More info:

Upvotes: 3

mirza
mirza

Reputation: 5793

This will do the job

$polish  = array('ć', 'ś', 'ł');
$replace = array('c', 's', 'l');
$text = 'A';
echo str_replace($polish, $replace, $text);

Upvotes: 0

Related Questions