2012-08-02 4 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

+0

게시글을 편집하고 전체 파일을 추가하겠습니다. 고맙습니다. – Garry

답변

0
  1. 먼저 파일 가져 오기 contens를 사용하여 컨텍스트를 검색하십시오.
  2. 그런 다음 preg_replace를 사용하여 교체 할 위치 또는 대상을 찾으십시오.
  3. 그런 다음 새 콘텐츠로 파일을 다시 작성하십시오.
관련 문제