2016-12-09 89 views
-6

enter image description herePHP如何保存後,保存秀PHP文件就像從文本此

indext.php-

1. text field to to enter value like **[text abc]** 
2. save text button 
3. change text button 

view.php-

此頁面顯示的文字從indext.php填充

+2

解釋清楚你的問題,並顯示您的代碼段,其相關t時的問題。 – Naga

+0

它,從零開始,基本上我不懂php,請幫我 –

+2

SO不是代碼寫作平臺。 – Naga

回答

-1

不知道你的全部要求,這應該讓你s tarted。我想你會想要將保存/更改的文本存儲到數據庫中。如果是這種情況,你需要建立在下面提供的基礎上。希望這可以幫助。

在此處輸入文字...

<?php 

if(isset($_POST['my_text'], $_POST['save']) && strlen($_POST['my_text']) > 0) 
{ 
    $my_text = htmlspecialchars($_POST['my_text'])."\n"; 
    if(!file_put_contents('view.php', $my_text, FILE_APPEND)) 
    { 
      echo "Unable to write to file"; 
    } 
    else 
    { 
      echo "Content Saved"; 
    } 
} 
elseif(isset($_POST['my_text'], $_POST['change']) && strlen($_POST['my_text']) > 0) 
{ 
    $my_text = htmlspecialchars($_POST['my_text'])."\n"; 
    if(!file_put_contents('view.php', $my_text)) 
    { 
      echo "Unable to write to file"; 
    } 
    else 
    { 
      echo "Content changed"; 
    } 
} 
else 
{ 
    echo "Please enter some text"; 
} 

?>