I like to count number of characters inside text box. 1. How to do it with PHP to echo it or/and 2. limit it to maximum with warning and/or 3. how to set it with automatic Javascript code when user filled text box?
@007JulienDec 15.2011 — #In my opinion, the best solution consists in using regular expressions...
With javascript, the single following lines count characters (we remove all other characters before). [CODE] // For lower or upper case letters
var result=str.replace(/[^a-z]+/gim,'').length; // For lower word characters depending of the local setting
var result=str.replace(/[W]+/gim,'').length; // For lower word or digits characters
var result=str.replace(/[WD]+/gim,'').length; [/CODE]
It is the same thing with PHP [code=php]$str=preg_replace("/[^a-z]+/gi","",$str); $result=strlen($str);// Or mb_strlen($str); with character encoding[/code]