2012-08-02 54 views
0

我似乎無法弄清楚如何使這個腳本寫入數據文件的部分。這裏是適用的代碼摘錄:如何打開和寫入文件的指定部分

$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'); ?> 

會有人介意幫助我在這一個嗎?這將非常感激。

+0

請參閱['fseek()'](http://php.net/fseek)。如果我們不知道文件是什麼樣的或者你想寫什麼的話,很難提供幫助。你能提供更多細節嗎? – drew010 2012-08-02 01:22:01

+0

你打賭,我會編輯帖子並添加整個文件。謝謝。 – Garry 2012-08-02 01:25:30

回答

0
  1. 使用file get contens首先檢索比賽。
  2. 然後使用preg_replace找到你想要替換的地方或者什麼。
  3. 然後用新內容重寫文件。
相關問題