PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
andys22
Forum Newbie
Posts: 7 Joined: Wed Mar 15, 2006 10:01 am
Post
by andys22 » Wed Mar 15, 2006 10:15 am
Hi, I have written some php code to pass the contents of a text document to a variable.
I now need to populate a form text area with that variable but am not sure how to do it as I am new to php.
My code looks like this:
Code: Select all
<FORM action="savetodb.php" method="post">
Update Wiki:<BR>
<TEXTAREA name="wiki_text" cols="100" rows="30"></TEXTAREA><BR>
<INPUT type="submit" value="Update Wiki">
<?php
$filename="wiki.data";
$fp = @fopen($filename, "r") or die("Couldn't open file");
$data = fread($fp, filesize($filename));
while(!feof($fp))
{
$data .= fgets($fp, 1024);
}
fclose($fp);
$values = explode("\r\n", $data);
TEXTAREA name="wiki_text" value=$data;
?>
</FORM>
It is a mess at the moment as you can see. All I am trying to do is get some text from a text file into my form. Any help would be gratefully recieved.
Thanks,
Andy.
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Wed Mar 15, 2006 10:20 am
Wrong forum, mate
Get the information from the file first, then:
Code: Select all
<?php
//get information
?>
<textarea name="wiki_text" cols="100" rows="30"><?php
print $textarea_information;
?></textarea>
Get the idea?
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Wed Mar 15, 2006 10:22 am
Be aware that if anyone puts a newline into their textarea, then it will be treated as two (or more) seperate entries in your text file as the textfile information is split by newlines...
andys22
Forum Newbie
Posts: 7 Joined: Wed Mar 15, 2006 10:01 am
Post
by andys22 » Wed Mar 15, 2006 10:29 am
I get the idea but will php rememeber the string variable after u close the tags i.e.
<?php //get variable $string ?>
<?php print $string ?>
andys22
Forum Newbie
Posts: 7 Joined: Wed Mar 15, 2006 10:01 am
Post
by andys22 » Wed Mar 15, 2006 10:32 am
It seems that it does. Cheers Grim. I will buy you a pint if you do the rest of my assessment for me. haha