182x Posted August 6, 2007 Share Posted August 6, 2007 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 } Quote Link to comment https://forums.phpfreaks.com/topic/63581-strlen-question/ Share on other sites More sharing options...
AndyB Posted August 6, 2007 Share Posted August 6, 2007 Why is that the case? Are you sure that your form processing code actually includes the error trap? Maybe what's on the server/in the folder isn't what you think. Quote Link to comment https://forums.phpfreaks.com/topic/63581-strlen-question/#findComment-316834 Share on other sites More sharing options...
182x Posted August 6, 2007 Author Share Posted August 6, 2007 Its just a simple text area its getting the characters from, I checked with MS word to endure the word count was correct and the error trap is being called/ Quote Link to comment https://forums.phpfreaks.com/topic/63581-strlen-question/#findComment-316839 Share on other sites More sharing options...
Psycho Posted August 6, 2007 Share Posted August 6, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/63581-strlen-question/#findComment-316842 Share on other sites More sharing options...
182x Posted August 6, 2007 Author Share Posted August 6, 2007 After more testing I am still having this problem. Could it simply be an issue with the server settings? Quote Link to comment https://forums.phpfreaks.com/topic/63581-strlen-question/#findComment-316944 Share on other sites More sharing options...
Psycho Posted August 6, 2007 Share Posted August 6, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/63581-strlen-question/#findComment-316954 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.