Elxis CMS Forum

Extensions => Components => Topic started by: herve34000 on September 12, 2011, 07:44:35

Title: Characters limit show
Post by: herve34000 on September 12, 2011, 07:44:35
Hi,

I have just a question about weblink components. We would like to show a characters limit. It's possible ? if, what we can do to add the code and where.  ;D

Thank you very much for you help.

Sample http://www.mediacollege.com/internet/javascript/form/limit-characters.html (http://www.mediacollege.com/internet/javascript/form/limit-characters.html)
Title: Re: Characters limit show
Post by: datahell on September 16, 2011, 20:25:43
In PHP for UTF-8 encoded strings using Elxis eUTF class:

<?php
$word = 'This is a really looooooooooong string';
echo (eUTF::utf8_strlen($word) > 20) ? eUTF::utf8_substr($word, 0, 17).'...' : $word;
?>

For Latin encoded strings you can use the standard php functions (faster)

<?php
echo (strlen($word) > 20) ? substr($word, 0, 17).'...' : $word;
?>