Re: Amount of characters a variable is able to contain

From: Date: Thu, 17 Nov 2005 16:30:14 +0000
Subject: Re: Amount of characters a variable is able to contain
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-40676@lists.php.net to get a copy of this message
I don't believe there is a way with file(), but there are alternatives. Firstly, does it need to be in an array? Does your script do anything else with $lineArray? If not, you'd be much better off just using file_get_contents() (http://php.net/file_get_contents) or, if you just want to output the file, readfile() (http://php.net/readfile), which dumps the file contents straight out to the visitor. If you do need to get it into an array, fgets() should work. Here's an example on the site (http://php.net/fgets), butchered to suit: $lineArray = array(); $handle = @fopen("/tmp/inputfile.txt", "r"); if ($handle) { while (!feof($handle)) {
       $lineArray[] = fgets($handle, 4096);
} fclose($handle); } That will get up to 4096 characters per line, and I'm sure increasing this isn't too complex :) Rob Ron Piggott wrote:
This is a sample of code which takes the $web_page and puts it into $message The problem I have is that I have lines in my $web_page files which are longer (have more characters) than $message is able to handle and chunks of web page text are simply truncated after the character limit has been reached. Is there a way to deal with this and allow $message (for example) to hold 500 or 1,000 characters --- twice of whatever the default setting is? Ron $lineArray = file($web_page); // make an empty variable first $message = ""; // concat all array element foreach($lineArray as $eachLine) { $message .= $eachLine; }


« previous php.db (#40676) next »