Rodrigo de Oliveira Costa wrote:
Actualy I went a slightly diffent way, I tried to use the file() like
on the script below and I get the content of the whole page but when I
try to get a single line from the array it all goes sideways. Here
goes the script with the correct urls, remembering that I'm using it
on the local server thats why I save it on the file to see if its
getting the right content:
$fc = file('http://www.fanfiction.net/s/979216/1/');
$f=fopen("some.txt","w");
foreach($fc as $line)
{
if ($line[85])
{ //look for $key in each line
fputs($f,$line[85]);
} //place $line back in file
echo "$line";
}
It shows the whole page but saves on the file something grambled that
I cant identify what it is.
Iknow that when opening the html result of the page that I need to get
the content its the second SELECT, and its actually on line 86, but
since the PHPEd dont use line 0 it should be right. Or I'm missing
something...
Thanks,
Rodrigo
HTML can't be parsed line-by-line since even a single tag can be broken
up onto multiple lines. And also, "if ($line[85])" simply checks if
there is a character in position 85 of the line. It looks like your code
is reading in a file, checking if each line is at least 85 characters
long, and then writing it out again.
I suggest you read in the whole file using file_get_contents(), and then
do the regex matching or strpos matching that I described in my previous
message. Also keep in mind that as of PHP 5 there is a
file_put_contents() function that lets you dump out a file in one go
(with higher performance than doing it yourself). php_compat also has a
copy of that function for other versions of PHP, although of course they
do it in PHP code so the performance benefits are slightly less.
Regards, Adam Zey.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php