I was hoping for a pointer to a good tutorial since I can't find anything that would go "all the way"... I'll struggle bit by bit, if you can assist, much appreciated.
My first hurdle - I can read the file but can't extract what's between <pre></pre> tags... here is what I've got so far:
<?php
// function to extract what's between the <pre></pre> tags
function find($start, $end, $data)
{
if(false !== ($pos = strpos(strtolower($data), strtolower($start))))
{
if($remove = stristr(($cropped = substr($data, $pos + strlen($start))), $end))
{
return trim(str_replace($remove, '', $cropped));
}
}
return false;
}
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://othersite.com/thisfile.txt");
curl_setopt($ch, CURLOPT_HEADER, 0);
// grab URL and pass it to the browser
//curl_exec($ch);
// grab URL and pass it to a variable
$data = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
// print to browser for check
echo(find("<pre>", "</pre>", $data));
?>
function find doesn't seem to work, I get everything written to the browser. But it works if I just read the local file:
<?
function find($start, $end, $data)
{
if(false !== ($pos = strpos(strtolower($data), strtolower($start))))
{
if($remove = stristr(($cropped = substr($data, $pos + strlen($start))), $end))
{
return trim(str_replace($remove, '', $cropped));
}
}
return false;
}
// set file to read
$file = 'localdata.txt' or die('Could not open file!');
// open file
$fh = fopen($file, 'r') or die('Could not open file!');
// read file contents
$data = fread($fh, filesize($file)) or die('Could not read file!');
// close file
fclose($fh);
echo(find("<pre>", "</pre>", $data));
?>
Any suggestions? Thanks in advance.