开发者

Is there a limit on PHP Variable Size?

I need to know if there is a variable limit size with PHP. I'm taking a string field from an SQL database and using echo to view it on a web page. The problem I am running into is that, when I view the web page, I don't see everything that is in the database field. Is there a limit on how much can be in a PHP variable? Is the开发者_如何学Gore a way I can make PHP read the entire entry from the database and not stop partway?


The amount of data a variable can hold is limited only by the amount of memory available to PHP. If you meet or exceed this limit, page execution will end and you will likely encounter a PHP error. Data contained in a variable will not be truncated silently.

Please note that most database field types do have explicit limits on the amount of data that can be stored in them. You may wish to confirm that the data really exists in the database as expected, and is not being truncated at the time it is inserted.

You should also check the output by viewing the HTML source. If the expected data appears when viewing the source, but does not display when the page is rendered in a browser, you may need to escape the data to remove any HTML entities that the browser is interpreting as markup.


The variable size is limited by the amount of memory available to PHP. To increase PHP's memory limit, you can modify the memory_limit in the php.ini file, if that option is available to you on your server. Otherwise, you can use ini_set at the beginning of your script.

ini_set('memory_limit','16M');


It's unlikely to be a memory problem. PHP wouldn't silently chop a string down to size, it'd just die with an out-of-memory error.

Is the string you're outputting truncated (end chopped off), or are parts missing from the middle? Remember than when viewing in a browser, anything that looks like an HTML tag will be interpreted as such. If your text contains a < somewhere, then anything after that MAY be hidden as part of an unknown tag, until a > is found later.

It's not likely to be a database problem either, as MySQL would issue an error if the size of the data exceeds the max_allowed_packet limit.


The solution was ini_set('odbc.defaultlrl', 65536);


The variable size is limited only by the amount of memory available to PHP. To increase PHP's memory limit, see this post:

http://drupal.org/node/207036

With regards to your problem, there must be some other factor affecting your output. Please post your code for help with that.


You could save an entire page (html, css and javascript) in one variable and just echo it. Your string should come out fine remember, that there is a limit to the length in your database. varchar is 255 if u run into length of string issues in your db try larger field types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜