I want to store a very long string in database using php. The size of string is 43kb. But when I pass this string to a php variable it does not support. It is supporting 16379 charcters in one string. Wwhen I add a single character more, Dreamweaver indicates s syntax error on that line. How I can store a long string of 50,000 characters in php variable.
-
Then just split it into two lines, e.g. `$str = '...'; $str .= '...';` - this might also interest you: http://stackoverflow.com/questions/3189040/what-is-the-maximum-length-of-a-string-in-php – Niko Jun 21 '12 at 10:50
2 Answers
You can store anything in a PHP string variable as long as you have enough memory to handle it.
43kb is not much as well as 16379 characters.
Dreamweaver (I'll try to be nice), should just have it's own memory limit, or is not used to handle such variable.
Didn't you try to run the PHP script?
By the way, if you've such big data to store in variable, I really advise you to move it from your PHP script to a file.
Note that by default, PHP has a memory_limit
of 128MB, but you increase it.

- 47,316
- 8
- 52
- 87
-
2actually strings have a limit of 2GB regardless, even if you allocate more than that to PHP: http://www.php.net/manual/en/language.types.string.php – Erik May 15 '14 at 14:37
There's no actual limit with PHP strings.
Here's a possible duplicate of your question: What is the maximum length of a String in PHP?
For your convinience, I'll paste Bill Karwin's response here:
However, a PHP script has a limit on the total memory it can allocate for all variables in a given script execution, so this effectively places a limit on the length of a single string variable too.
This limit is the
memory_limit
directive in the php.ini configuration file. The memory limit defaults to 128MB in PHP 5.2, and 8MB in earlier releases.If you don't specify a memory limit in your php.ini file, it uses the default, which is compiled into the PHP binary. In theory you can modify the source and rebuild PHP to change this default value.
If you specify
-1
as the memory limit in your php.ini file, it stop checking and permits your script to use as much memory as the operating system will allocate. This is still a practical limit, but depends on system resources and architecture.