问题描述:

indext.php-

1. text field to to enter value like **[text abc]**

2. save text button

3. change text button

view.php-

this page show text from text filled from indext.php

网友答案:

Without knowing your full requirements, this should get you started. I imagine you are going to want to store the saved/changed text into a database. If this is the case, you need to build upon what is provided below. Hope this helps.

Enter Text Here...

<?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";
}

?>
相关阅读:
Top