# Edit variable value in PHP file? - simple CMS

**URL:** https://forum.kirupa.com/t/edit-variable-value-in-php-file-simple-cms/136748
**Category:** Uncategorized
**Created:** [February 8, 2005, 7:50am UTC](https://forum.kirupa.com/t/edit-variable-value-in-php-file-simple-cms/136748 "2005-02-08T07:50:26Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![polishbroadcast](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@polishbroadcast](https://forum.kirupa.com/u/polishbroadcast)
#### Post date: [February 8, 2005, 7:50am UTC](https://forum.kirupa.com/t/edit-variable-value-in-php-file-simple-cms/136748/1 "2005-02-08T07:50:26Z")

</div>

I’m trying to create a very simple way to update content on a website using a php script to edit the php pages themselves. All of the pages, index.php, about.php etc. only contain: a variable

```auto
$body

```

which is the text of the page and an

```auto
include();

```

call which loads the layout of the page.

I have this which can edit the full php page:

```php
$mydir = ".";
$file = "index.php";
$curdir=dir($mydir);

$writefile = $_REQUEST['writefile'];
$text = $_REQUEST['text'];
if($writefile)
{
    $fd=fopen($mydir."/".$file, "w");
    fwrite($fd, stripslashes($text));
    fclose($fd);
    echo "<font color=red><strong>File updated</strong></font>";
    echo "<meta http-equiv=\"Refresh\" content=\"3; URL=$PHP_SELF\">";
}
elseif($file)
{
    $fp=fopen($mydir."/".$file, "r"); // $mydir$myfile
    while(!feof($fp)) {
        //$content .= fgets($body);
        $content .= fgets($fp, 4096);
        }
    fclose($fp);
   
    echo "<FORM ACTION='$PHP_SELF' METHOD='post'>";
    echo "<input type=hidden name=writefile value=true>";
    echo "<TITLE>Editor</TITLE>";
    echo "<TEXTAREA ROWS='20' COLS='80' NAME='text'>";
    echo "$content";
    echo "</TEXTAREA><BR>";
    echo "<input type='submit' value='Update'><br></form>";
}

```

It works great but how can i make it so it only loads the value of

```auto
$body

```

into

```auto
$content

```

instead of the whole php page? Since i’m only needing to edit the text, i only want to load that into the text form field. Thanks!
