note 89714 added to function.mb-substr
| From: | Amaroq at osu1 dot php dot net | Date: | Fri, 20 Mar 2009 08:07:59 +0000 |
| Subject: | note 89714 added to function.mb-substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152181@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
document.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: 64.71.164.2
Probable Submitter: 76.16.128.198
----
Manual Page -- http://www.php.net/manual/en/function.mb-substr.php
Edit -- https://master.php.net/note/edit/89714
Del: integrated -- https://master.php.net/note/delete/89714/integrated
Del: useless -- https://master.php.net/note/delete/89714/useless
Del: bad code -- https://master.php.net/note/delete/89714/bad+code
Del: spam -- https://master.php.net/note/delete/89714/spam
Del: non-english -- https://master.php.net/note/delete/89714/non-english
Del: in docs -- https://master.php.net/note/delete/89714/in+docs
Del: other reasons-- https://master.php.net/note/delete/89714
Reject -- https://master.php.net/note/reject/89714
Search -- https://master.php.net/manage/user-notes.php