darkfact Posted October 16, 2010 Share Posted October 16, 2010 I'm trying to increment a numerical value and after several hours of reading haven't come up with a solution. this may be too much information but here it is; I'm using this code to change the values in r5include.html <?php $ident = $_POST['ident']; ?> <?php $ident2 = ($ident . 2); $filename = 'r5include.html'; $string = file_get_contents($filename); $old = array("'images/up.jpg'","add.html' target='_blank'"); $new = array("'$ident/$ident2.jpg'","$ident.html' target='iframe2'"); $data = str_replace($old,$new,$string); $handle = fopen($filename, "w+"); fwrite($handle,$data); fclose($handle); ?> but before I do that I'm copying the original to a temp file with this code: <?php $filename = 'r5include.html'; $string = file_get_contents($filename); $tempfile = 'temp.html'; $handle = fopen($tempfile, "a"); fwrite($handle,$string); fclose($handle); ?> This is what goes to temp.html: <img height=75 src='images/up.jpg' hidefocus='true' usemap='#record51' /> <map name='record51'> <area shape='rect' coords='0,0,75,75' href='add.html' target='_blank'> I would like to increment the 2 instances of record51 to record52 and increment again each time the process is initiated. And then append it to r5include with this: <?php $myFile = "r5include.html"; $fh = fopen($myFile, 'a') or die("can't open file"); $filename = 'temp.html'; $string = file_get_contents($filename); fwrite($fh,$string); fclose($fh); ?> So the question is is it possible? and if so how do I increment the record number? Thanks, Quote Link to comment Share on other sites More sharing options...
Buddski Posted October 16, 2010 Share Posted October 16, 2010 I am not exactly sure what you are trying to do.. My first question is what is this line doing? $ident2 = ($ident . 2); and what is contained in the $_POST['indent']? You say you are trying to increment a numerical value but I cannot see that in your code. Quote Link to comment Share on other sites More sharing options...
darkfact Posted October 16, 2010 Author Share Posted October 16, 2010 My first question is what is this line doing? $ident2 = ($ident . 2); $ident2 returns the value of $ident with a 2 appended to it. and what is contained in the $_POST['indent']? An alpha numeric value--whatever is entered in the form. You say you are trying to increment a numerical value but I cannot see that in your code. I would like to increment the 2 instances of record51 to record52 and increment again each time the process is initiated. Quote Link to comment Share on other sites More sharing options...
darkfact Posted October 16, 2010 Author Share Posted October 16, 2010 nevermind. It was late and I was over-thinking it. I just added to my str_replace and replace record51 with the value of $ident. The form won't allow it if it already exists and all I needed was a unique name for each entry. Problem solved. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.