PHP String Size Limits


You probably won’t need to store an entire dictionary in a single PHP string, but it can be useful to know exactly how much data you can assign to a single variable. Although there’s a practical limit to the amount of data that you can store in a PHP string, you can conveniently alter that limit by editing a particular file.

PHP Language

  • PHP is a programming language that is widely used to develop database-driven and interactive Web pages. Like most programming languages, PHP allows the developer to create variables and assign data to be stored in them. One type of variable that you can use for data storage in PHP is called a string.


  • In PHP, a “string” is a sequence of alphanumeric characters, spaces, punctuation and other symbols. When you store data such as a word, a phrase or a name in a variable, you are effectively creating a string. Strings allow you to perform a variety of operations in PHP. For example, you can store or retrieve a username from a database or display randomly generated greetings on your Web page.

Maximum String Size

  • Most programming languages limit the number of characters that can be stored in a string, but PHP does not. This does not mean that you can store unlimited data in a PHP string, however. While there’s no limit on string length, a limit is imposed on the overall amount of data that a PHP script may use. This limit, expressed in bytes, can be changed by editing the “php.ini” configuration file.

Editing php.ini

  • The “php.ini” file is located in the PHP installation directory on your server and it contains a list of directives, or rules, that your server must follow. The "memory_limit" directive in this file is the one that you must edit if you want your PHP scripts to be able to manipulate extremely long strings. By default, the memory_limit directive is set at 128MB. If you anticipate that your script may need to handle strings containing more than that amount of data, edit the memory_limit value in your php.ini file using a text editor such as Notepad. However, you should be aware that there’s a good reason the memory_limit directive exists: a poorly conceived script may consume all of the available memory on a computer, so if the memory_limit value is set too high, it could slow down or crash your server.

Related Searches


Promoted By Zergnet


Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!