Reputation: 483
first of all: I really love this site and I think this is the best forum for programming :)
Now to my problem, which I try to display using code and comments:
$file = fopen ($URL, "r");
// $URL is a string set before, which is correct
// Also, I got the page-owners permission to acquire the page like that
if (!$file)
{
echo "<p>Could not open file.\n";
exit;
}
while (!feof ($file))
{
$buffer = fgets($file);
$buffer= strstr($buffer, "Montag</b>");
// If I don't use this line, the whole page gets displayed...
// If I use this line, only the first line after the needle gets displayed
echo $buffer;
}
fclose($file);
So basically, I'm able to display the whole page, or one line after the needle, but not everything after the needle....
I tried to find a solution using the PHP Reference, the Stackoverflow Search engine and of course google, but I couldn't find a solution, thanks for everybody willing to help me.
Greetings userrr3
Upvotes: 1
Views: 991
Reputation: 21553
You are only grabbing one line at a time from the file using fgets()
DOCs if you want the whole file then use file_get_contents()
DOCs instead:
$file = file_get_contents($URL);
$buffer= strstr($file, "Montag</b>");
// If I don't use this line, the whole page gets displayed...
// If I use this line, only the first line after the needle gets displayed
echo $buffer;
This can be achieved using PHPs substr()
DOCs function combined with strpos()
DOCs:
$buffer = substr($buffer, strpos($buffer, 'Montag</b>'));
This will grab all the text after the first occurrence of the needle Montag</b>
.
$file = file_get_contents($URL);
$buffer = substr($file, strpos($buffer, 'Montag</b>'));
echo $buffer;
Upvotes: 2