1

I notice the problem when I use the character ¦. For the 3000 character limit, I can fill the textarea with 3000 ampersands. The javascript showing the string length says 3000 and when I post the text, php says it's 3000. If I try 3000 of ¦ then javascript again shows 3000, but php shows a lot more, in the 5000's. ¦ has a html code ¦ and ¦ so I don't know why php is showing a problem. Why is this?

Edit: PHP shows that each ¦ has a string length of 2, while other characters have the usual 1. I notice that any character with an ASCII code higher than 160 has a php string length of 2: http://www.ascii.cl/htmlcodes.htm

7
  • please some code how you are counting length in php.. Commented Jun 7, 2013 at 5:31
  • When the textarea is posted I'm just echoing strlen($_POST['text']) Commented Jun 7, 2013 at 5:32
  • 1
    strlen('|'); prints 1 in php. Commented Jun 7, 2013 at 5:34
  • please post echo $_POST['text']; Commented Jun 7, 2013 at 5:36
  • echo strlen("¦"); echoes 2 Commented Jun 7, 2013 at 5:39

1 Answer 1

2

You may be dealing with multicharacter UTF-8 chars. To have those counted correctly, assuming your files are actually UTF-8, try this:

mb_internal_encoding("UTF-8");
mb_regex_encoding("UTF-8"); // Not actually needed in this case, but add it if you use preg_ functions
echo mb_strlen("¦");

mb_* functions are meant to deal with multibyte characters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.