Re: Proposed change to modifier.truncate.php to respect HTML entities

Bharat Mediratta <[email protected]>
Newsgroups gmane.comp.php.smarty.devel
Message-ID <[email protected]>
messju mohr wrote:

> On Fri, Jun 04, 2004 at 05:35:41PM -0700, Bharat Mediratta wrote:
>>I chose to create a new modifier based on the truncate modifier which 
>>does the equivalent of html_entity_decode() on the input string, then 
>>does the truncate calculation, then does an htmlentities() on the result 
>>before returning it.  This is perhaps not the most efficient approach, 
>>but it is simple in the code (and I am not particularly concerned about 
>>efficiency in this case).
...
> html-encoded strings are not the only problematic input to
> truncate. AFAIK multi-byte-character-sets can also cause probles.
> 
> maybe we can find a solution that solves both?

I don't know enough about the way that PHP manages multibyte strings to 
know what's the right solution for this problem.  Clearly, we could use 
(for example) mb_substr() instead of substr() which would do the right 
thing if we've got the encoding set properly for the string. 
Alternatively, we could expect that the tool using Smarty has set the
mbstring.func_overload feature in PHP to remap substr() correctly.

I think that this is probably a larger issue in Smarty, since any place 
where we may work with substrings in potentially encoded content can 
lead to this problem.  I'm not familiar with all the Smarty plugins, but 
I imagine at least a few of them do similar string manipulations.

For now, I'd rather solve one problem at a time.  If we can get the 
encoding switch in now, it would enable me to use the Smarty plugin.  If 
at some later date we add support for multibyte strings at a more common 
level across all plugins then we could make that apply to this modifier 
also.  If you're interested in taking that approach, I can send you what 
I have.  You can see a copy of my code here:

http://cvs.sourceforge.net/viewcvs.py/gallery/gallery2/lib/smarty_plugins/modifier.entitytruncate.php?rev=1.1&view=auto

It's just a couple of lines different from the original modifier.

-Bharat

-- 
Smarty Development Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.