php - Replace all html special characters in Smarty

317

I want to truncate a string in Smarty
This is the scenario:
The string is "Test!abc". Maximum characters allowed = 5.
Smarty gets string.
If I use{$string}, I get the desired result "Test!abc"
If I use{$string|truncate:5:"..":true} I get "Test&.."

How can I make truncate after html chars conversion. Prefer not to make it in php.
I know about "replace", but it will look like "|replace..|replace..|......"

627

Answer

Solution:

You could try something like:

{$string|html_entity_decode:2:"UTF-8"|truncate:5:"...":true|htmlentities:2:"UTF-8"} 
708

Answer

Solution:

If you're using Smarty 3.1 you can have a look at the unescape modifier.

{$string|unescape:"entity"|truncate:5}
275

Answer

Solution:

In Smarty 2 you can try this one

{$string|html_entity_decode|truncate:5}

People are also looking for solutions to the problem: php - Query in Yi2 and checking a relationship in another table

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.