Jump to content

find and replace numbers


darkfact

Recommended Posts

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,

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.