Jump to content

strlen question


182x

Recommended Posts

Hey guys I am using the following code in order to ensure that a user does not exceed the limit of 2000 characters when processing a form. I also have some javascript which informs the user how many characters they have left and the php code is just a fail safe incase javascript is not enabled. However when using the code below if I have 2001 charaters it is still accepted it goes to around 2300 before it works I was just wondering why this is the case? Thanks

 

if(strlen($_POST['text']) > 2000)

{
//error
}

else{
//ok
}

Link to comment
Share on other sites

If you are using MS Word you should know that it does not count new line characters when counting characters, PHP does. however, in this case you would end up with the opposite results of what you explained.

 

In addition to counting newline characters also be aware that depending upon your server configuration, special chatracters (such as quote marks) may be "escaped" on your processing page. If so, any special characters that are escaped would be counted as two characters because of the backslash that would proceed them.

Link to comment
Share on other sites

Well, your testing, if done right, should help you to determine where the discrepency is. Try echoing the POST data to the page to see if characters are being added or dropped.

 

however the problem you described makes no sense. The problem with the way WOrd counts vs. PHP and the escaping of characters would make PHP count more characters. So, you should be getting the error warning  with less than 2000 characters, not more.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.