Jump to content

Problem with STRING Variable....?


whit3fir3

Recommended Posts

I need to see if someone can point out something that I have missed or maybe even point me in the right direction on something.  I have a PHP script that I have run into a problem on.  The basic idea of the script is that it will send out HTML formatted emails to users of my web site.  The problem I am running into is storing the HTML content in memory so I can do a str_replace() looking for certain markers in the HTML and replace them with lets say the users name and custom links that pertain to the particular user that the email is going to.  Currently the HTML is being stored in a MySQL database, but I have already tried reading it from a flat file.  Each time I only get the first 1024 characters returned.  The problem seems to be that I am running into a PHP STRING limitation.  From the reading that I have done on the subject, the limit should be 1024 characters PER LINE with the variable able to hold somewhere around 8MB worth of data.  I can tell you that it does not matter how many \n I put into the HTML I still only get the first 1024 characters.  Is there a way I can get the entire HTML file (about 12k characters) in memory so I can work with it and hand it off to the mail function?

 

Thanks,

 

whit3fir3

Link to comment
Share on other sites

I didn't know there was such a limit... weird... always thought it would be okay if it didn't use more than the memory_limit...

 

you can try to edit the memory limit in the php.ini file:

memory_limit

 

you can also just try to put this in the start of the script:

ini_set('memory_limit', '128M');.

for example...

Link to comment
Share on other sites

Boom.dk

 

As far as posting code the section that is problematic is just a database select or reading from a TXT file. 

 

        $sql = "SELECT `msg` FROM `email_messages` WHERE `id`=3";
$result = mysql_query($sql);
while ($line = mysql_fetch_assoc($result))
{
	$origEmail = $line['msg'];
}

 

What I can tell you from running this through a debugger is that the entire HTML is in the database.  A simple command line SELECT verifies and MySQL is returning the entire page as verified by a TCPDUMP.  This bring be back to PHP and a 1024 character string limit or some sort.  What I can tell you that I found weird is that when looking at the values in a debugger $line['msg'] also only contains 1024 characters.

 

MMDE

 

I try taking the memory limit up, but I really do not think that is going to have the desired effect.  The problem I am running into is a limit on a single variable not a resource limitation.  I'll give it a shot here in a few minutes and let you know if it works.

 

Thanks,

 

whit3fir3

Link to comment
Share on other sites

There's no specific small 1024 limit to a variable size.

 

If the symptom was present both for data that was read from a file or from a database, the symptom is being caused by something that is common to both those methods. Either there's something in your code or the actual data causing it, something going on with your server/php causing it, or something with the method you are using to view the result that is causing it.

 

Since phpmyadmin is just a php script, it would likely show the same symptom if the problem is being caused by something with your server/php (assuming that phpmyadmin is running on the same server as your script.) That kind of narrows down the problem to something you are doing in your actual code or with the actual data (phpmyadmin would display the data literally by passing it through htmlentities before outputting it.) Best guess is you have something in your data that is broken HTML and it causes the visible output in your browser to appear to stop at a certain point. Have you done a 'view source' in your browser so you know what exactly is being output?

 

I recommend that you post some code and data, it could be a simplified version, as long as it reproduces the problem, so that someone else can duplicate the problem to either confirm or eliminate your code as the cause of the problem, both for using a flat file and a mysql database (seeing the code that produces the symptom for both methods would help to narrow down the problem.)

Link to comment
Share on other sites

  • 4 weeks later...

I have the same kind of trouble, i'm reading a web page in a string variable.

In the code i read the page in 1000 byte chunks and concatenate them to a buffer variable, the only problem is that this buffer has into only 1024 bytes.

It cut all the rest without giving error in the concatenation.

		for(;	{
			$error=$http->ReadReplyBody($body, 1000);
			if($error!="" || strlen($body)==0)
				break;
			$buffer .= $body;
		}

 

Link to comment
Share on other sites

  • 2 years later...

I had a similar issue and it was the debugger that was displaying misleading information, the string was not actually truncated.

It appears only the first 1024 chars are shown in the pdt debugger, even the length member of the string shows 1024 but the true length is shown in brackets!

 

You can see the full string by selecting 'change value' 

 

see this post

http://www.eclipse.org/forums/index.php/m/492856/

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.