No matter how many different ways I try to do this, it will never work.
The code will always return 1 for $timeshere and never replace the number in the preg_replace line.
$IP = $_SERVER['REMOTE_ADDR'];
$IPfile = "logs\\IP.html";
if (!file_exists($IPfile)) {
fopen($IPfile, 'w');
}
$IPs = @file_get_contents($IPfile);
if (preg_match("#<p><i>{$IP}<\/i>#i", $IPs)) { //if your IP is found in the flat file
$timeshere = preg_match("#<p><i>{$IP}<\/i> accessed <b>([^<]*)<\/b> Times<\/p>#i", $IPs); //set $timeshere to amount in file
$timesherenow = $timeshere + 1;
preg_replace("#<p><i>{$IP}<\/i> accessed <b>([^<]*)<\/b> Times<\/p>#i", "<p><i>{$IP}<\/i> accessed <b>{$timesherenow}<\/b> Times<\/p>", $IPs);
file_put_contents($IPfile,$IPs,LOCK_EX);
} else {
$IPs .= "<p><i>{$IP}</i> accessed <b>1</b> Times</p>\n";
file_put_contents($IPfile,$IPs,LOCK_EX);
}
I wrote this code my self, so it is probably going to look pretty sloppy.