Forum Moderators: coopster
<?php if ($fp = fopen('http://www.example.com/wrapper.html', 'r')) {
$content = '';
// keep reading until there's nothing left
while ($line = fgets($fp, 1024)) {
$content .= $line;
}
$myFile = "testFile.html";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
// do something with the content here
// ...
} else {
// an error occurred when trying to open the specified url
}
?>
Which does it pretty well except I need it to stop at a word in the middle and read no further.. the word is also higher up in the code, but the word I need it to stop at is in all caps.. the other instances are not.. also how could I strip out other pieces of code such as <head></head> and the like? can anybody help?
You could also use file_get_contents [uk2.php.net] to read your url into a string. As if fopen wrappers have been enabled they will work for both fopen and file_get_contents.