This is what I have and it works great except I don’t want the world “new” in front of new items I want to use an image…
[php]
define(‘UPDATE_INTERVAL’, 60 * 60 * 6); // set update interval, eg 6 hours
define(‘DATAFILE’, ‘data.json’); // file to store the data in
$timeSinceUpdated = 0;
// if the datafile exists
if (file_exists(DATAFILE)) {
// get the time when the datfile was last updated/created
$lastModified = filemtime(DATAFILE);
// get the time passed since the file has been updated/created
$timeSinceUpdated = time() - $lastModified;
// decode the data from the datafile
$data = file_get_contents(DATAFILE);
$data = json_decode($data);
}
// if the file does not exist, or the the update interval has passed
// perform curl request and update the data
if (!file_exists(DATAFILE) || $timeSinceUpdated >= UPDATE_INTERVAL) {
include(‘simple_html_dom.php’);
// Create DOM from URL or file
$html = file_get_html(‘http://sportsfeedia.com/nfl/’);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $html);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
$str = curl_exec($curl);
curl_close($curl);
file_get_contents(‘data.json’);
// overwrite the data
$data = array();
// Find all links, and their text
foreach ($html->find(‘a[class=itemtitle]’) as $elm) {
$link = $elm->href;
$text = $elm->plaintext;
if(substr($text, 0,3) == "new") {
$text = substr_replace("new", "<img src='new.png' height=28 width=28> ", 0, 3);
}
// add new data to array
$data[] = array(
$link,
$text
);
}
// json encode the data and save to the datafile
file_put_contents(DATAFILE, json_encode($data));
}
// output links
foreach ($data as $contents) {
list($link,$text) = $contents;
?>
Works great except one tiny glitch that I cannot get to work… it replaces the ‘new’ with the image but it doesn’t display the rest of the string… if it isn’t a new item ‘new’ doesn’t appear in front of the item it shows with no problem…
So when it’s going by in its newsticker it’ll show either the “text” - Headline or “new.png” and “Read More”
the link works but no “text” - Headline appears.
What am I missing here? LOL Probably something simple… usually is…
Thank you!