note 89713 added to function.substr

From: Date: Fri, 20 Mar 2009 08:04:07 +0000
Subject: note 89713 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-152180@lists.php.net to get a copy of this message
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. ---- Server IP: 208.69.120.35 Probable Submitter: 76.16.128.198 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- https://master.php.net/note/edit/89713 Del: integrated -- https://master.php.net/note/delete/89713/integrated Del: useless -- https://master.php.net/note/delete/89713/useless Del: bad code -- https://master.php.net/note/delete/89713/bad+code Del: spam -- https://master.php.net/note/delete/89713/spam Del: non-english -- https://master.php.net/note/delete/89713/non-english Del: in docs -- https://master.php.net/note/delete/89713/in+docs Del: other reasons-- https://master.php.net/note/delete/89713 Reject -- https://master.php.net/note/reject/89713 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#152180) next »