3

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 there a way I can make PHP read the entire entry from the database and not stop partway?

1
  • How big is the column you're trying to output? Commented Jul 7, 2011 at 15:07

6 Answers 6

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@user418232: Can you update your question with an example of the HTML source that is generated, and explain what is missing?
7

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');

1 Comment

If this is the problem, the data will not be truncated silently. Logs or other output will reveal such an issue, and page execution will stop prematurely.
2

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.

7 Comments

EPS - encapsulated post-script? That's basically programming code, so may well have a < in there. Try viewing the SOURCE of the page, instead of just directly in the browser window.
I m sure its not containing >. Even if i can view the data via view source it wont help because i have to fetch the data from sql and insert into mysql ....
Yes, but remember you're viewing in a webpage to see if it's truncated. You said you're echoing. View the source to make sure your browser's not lying to you.
And again, if it was a memory issue, the PHP script would simply die. Even doing something like echo strlen($your_eps_string) to see how long PHP thinks it is, v.s. what the reported length is in the database.
When i match both the fields in Mysql and Sql server they are not the same as well.Its chopped off
|
2

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

1 Comment

what is this? any explanation?
0

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.

3 Comments

I'm unsure of where he mentioned Drupal at any point in his post.
The link may go to the drupal site but it explains exactly what you posted above.
Indeed, the Drupal resource is the best explanation I've found for upping the memory limit and is common to all PHP apps.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.