0

I can't seem to figure out how to make this script write data to the section of the file. Here is an excerpt of the code that applies:

$file = $url.'.php';   
if (!$file_handle = fopen($file,"a+")) 
{ 
echo $lang['cannot_open_file']; 
} 
if (!fwrite($file_handle,stripslashes(html_entity_decode($data))))
{ 
echo $lang['file_is_not_writable']; 
}
fclose($file_handle);  
echo ($lang['success']);
echo ('<meta http-equiv="Refresh" content="4;url='.$url.'.php" />');
}
}

?>

<form action="<?php echo $url;?>.php" method="post">
<?php echo $lang['name']?> <span style="font-weight:100;">(<?php echo $lang['required']?>)</span>:<br />
<input class="textfield" type="text" name="name" value="" /><br />
<?php echo $lang['website']?> <span style="font-weight:100;">(<?php echo $lang['without_http'];?>)</span>:<br />
<input class="textfield" type="text" name="site" value="" /><br />
<?php echo $lang['message']?>:<br />
<textarea class="textarea" rows="2" cols="25" name="message"></textarea><br />
<img src="captcha-image.php" alt="Image verification" />  <br />
  <?php echo $lang['value_from_the_image'];?>:<br />
<input class="textfield" type="text" name="img_ver" value="" /><br />
        <input type="reset" name="reset" value="<?php echo $lang['reset'];?>" />
        <input type="submit" name="send" value="<?php echo $lang['send'];?>" />
      </form>
<hr>
<h3>Comments:</h3>
<!--comments -->

<?php include('../templates/footer.php'); ?>

Would anyone mind helping me out on this one? It would be much appreciated.

Rikesh
  • 26,156
  • 14
  • 79
  • 87
Garry
  • 251
  • 2
  • 13
  • See [`fseek()`](http://php.net/fseek). Hard to help though if we don't know what the file looks like or where you want to write to it. Can you provide more details please? – drew010 Aug 02 '12 at 01:22
  • You bet, I'll edit the post and add the entire file. Thank you. – Garry Aug 02 '12 at 01:25

1 Answers1

0
  1. Use file get contens to retrieve the contens first.
  2. Then use preg_replace to find where or what you want to be replaced.
  3. Then rewrite the file with the new content.
Johndave Decano
  • 2,101
  • 2
  • 16
  • 16