Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
How long can a string be?

Posted by enquirer (enquirer), 17 March 2003
I'm looking for the answer to this question that I found at a quiz site. It says you would know the answer.I have a text string that is 58,880 text characters long and when I try to run my PHP script I get an error that says 'expecting "," or ";" on line 12...' which is only 8 lines into my 650+ line variable definition. I found a few PHP forums with the same question but the answer is usually 'There shouldn't be a limit'.

PHP Programming quiz, level Basics, question 13
Quote:
Question: The maximum length of a string held in a variable is ...
Answer 1: There is no practical limit
Answer 2: 1024 bytes
Answer 3: 10240 bytes
Answer 4: Just under 4 Megabytes


Posted by admin (Graham Ellis), 17 March 2003
The answer (Quiz site) is "no practical limit" and indeed I have often worked with strings that are far longer than 60k..  It  could be that there's a lower limit for the " operator or the ' for a  literal string, or  perhaps you have one of those characters actually in your string?  

Solutions ...
a) Check your string for " or ' embedded in it
b) Build up your string using . (period) operators from a series of shorter strings.

The quiz site mentioned - http://www.phpquiz.co.uk is one of "ours" by the way - so I'm able to quote / post from it here at will without any copyright problems  

Posted by enquirer (enquirer), 17 March 2003
Thanks for the quick response. It was actually another simple syntax error that had nothing to do with the string itself. My editor uses word wrap but still numbers the lines, although PHP sees all 650+ lines as just one, so my real problem WAS on line 12 when i took word wrap off.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho