Ok, nps. What I would personally recommend is looping through the string, then when an instance is found, a variable is changed, depending on the variable, the instance will/won't be changed, like so:
PHP Code:
$instance = 1;
for ($i=0; $i<=strlen($string); $i++) {
if (substr($string, $i, 4) == "<tr>") {
if ($instance % 2 == 0) {
substr_replace($string, "<tr class=\"Body2\">", $i);
}
$instance++;
}
}
This will change all 'even' instances, basically every second instance.
still no go. I will post the whole file this time.
PHP Code:
<?
$url = "http://www.chl.ca/CHL/topten.html"; // Trailing slash when not using filename
$file = "includes/cache/CHL_ranking_cache.html"; // file to write to. remember to chmod 777 to not get errors
$unique_start = '<TD VALIGN=TOP><div id=smtext>Rank</TD>'; // Where to begin to grab
$unique_end = '<br><br><b>CHL WEEKLY TOP TENS</b><br>'; // Where to end the grab
//$cache_tolerance = 43200; // How many seconds old the cache file can get Set at 12 hours
$cache_tolerance = 1; // How many seconds old the cache file can get Set at 1 second
function check_domain_CHL($target) { // tests if domain is accessible by opening a socket to it
$fetch_domain = parse_url($target);
$fetch_domain = $fetch_domain[host];
$socket_handle = fsockopen("$fetch_domain", 80, $error_nr, $error_txt,30);
if(!$socket_handle)
{
echo $target . ' could not be reached.<br>';
return "false";
}
return "true";
} // function check_domain_CHL
// check how old the cache file is
if (file_exists($file)) {
clearstatcache(); // filemtime info gets cached so we must ensure that the cache is empty
$time_difference = time() - filemtime($file);
} else {
$time_difference = $cache_tolerance; // force update
}
if ($time_difference >= $cache_tolerance){ // update the cache if need be
update_cache_CHL($url,$unique_start,$unique_end,$file);
}
write_cache_CHL($file); // we always only output from cache