note 89713 deleted from function.substr by danbrown

From: Date: Fri, 20 Mar 2009 12:57:49 +0000
Subject: note 89713 deleted from function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-152203@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- When dealing with submitted forms that you've imposed a character limit on, you must remember that functions that count characters consider "\r\n" to be two characters. If you want strlen and mb_strlen to count accurately and in agreement to javascript's form.input.value.length, you must replace all occurrences of "\r\n" with "\n". <?php $accurate_str = substr(str_replace("\r\n", "\n", $initial_str)); ?> If I had thought of this starting out, I would have saved myself several hours of trouble trying to get php to cut a message to the same length that my auxiliary javascript validation imposed on it.

« previous php.notes (#152203) next »