• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Tough One For Ya

Dan

Bullah
NLC
I have this textarea in site A
In site B I have say stuff.html

What I want to do is have the content of stuff.html displayed in the textarea in Site A.

Sounds simple and sounds like it can be done by just displaying some PHP code between <texarea> and </textarea>. Well, tried and errored and I can't get it to work.

I have searched Google and saw many recommendations of the following:

PHP:
<textarea>
<?Php
$file = $_SERVER['DOCUMENT_ROOT'] . "/text.txt"; //Path to your *.txt file
$contents = file($file);
$string = implode($contents);

echo $string;
?>
</textarea>

All that happened was the included PHP was displayed in the textarea.

Any suggestions?
 
1) Is the file on site A a .php file?
2) Depending on your install, "<?Php" is wrong, as it can be case dependant. Try: "<?php"
 
if i am understanding what it is you are trying to do, this is what you will need.

this will open it for editing.
PHP:
$filename = "DOCUMENT ROOT PATH AND FILENAME HERE.php"; // FILENAME
$handle = fopen($filename, "r"); // OPEN THE FILE
$contents = stream_get_contents($handle); // GET THE CONTENTS OF THE FILE
fclose($handle); // CLOSE THE FILE

// ECHO OUT THE CONTENTS FOR THE FILE THAT WE STORED IN THE VARIABLE
echo 	'<textarea name="page_content" rows="15" cols="100" >'.$content.'</textarea>';

when you go to update that file, you will need...
PHP:
$handle = fopen("DOCUMENT ROOT PATH AND FILENAME HERE.php","w");
// IF THE PAGE UPDATED SUCCESSFULLY, DISPLAY SUCCESS MESSAGE.
if(fwrite($handle, $contents)) { echo 'woohoo!!!'; }
else { echo 'wtf!!!'; } // ECHO ERROR
fclose($handle);

**EDIT**
Dan, notice the "r" in the fist block of code, and the "w" in the second block. the "r" is for reading the file, and "w" is for writing to the file.

the only problem i see with what you are doing Dan is that you are trying to grab a file on another site. now, if this site and file happen to be on the same server, you can do that bu putting the server root and the other site where the path is needed, but, if it was say, on my site, and you were trying to pull it to yours, then you would need to scrape the page instead with curl and then parse out the part that you want to the textarea, and as for updating, you wouldnt be able to update it if it is on my server. hope that helps.
 
Last edited:
Cheers guys.

Justin, I wanted to display the information from a file at Site A inside a textarea in site B. The reason I wanted a text area is because it looked better. But I changed to an iFrame and it did the trick with some CSS styling.

Thanks again.
 
in that case Dan, use this bro...

PHP:
# Use fopen to scrape Google's homepage and
# store it's HTML code in the $contents variable
#$handle = fopen("http://www.methodcomptech.com/", "rb");
$handle = fopen("FULL HTTP URL HERE", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
# Display all content
echo "<textarea>".$contents."</textarea>";
 
iBrights solution is very elegant, but if you want to use your original code, just move the textarea tags to the echo and it should work, providing the rest of the php is good :)

PHP:
<?Php
$file = $_SERVER['DOCUMENT_ROOT'] . "/text.txt"; //Path to your *.txt file
$contents = file($file);
$string = implode($contents);

echo "<textarea>".$string."</textarea>";
?>
 
haha, i didnt even look at the original code for errors. just started posting code that he could use as a solution. :p
 
My input because why not.

PHP:
<?php
echo "<textarea>" . file_get_contents("text.txt") . "</textarea>";
?>

Simples!
 
My input because why not.

PHP:
<?php
echo "<textarea>" . file_get_contents("text.txt") . "</textarea>";
?>

Simples!

That was one of the first methods I tried mate. Didn't work. Just displayed "file_get_contents("text.txt")." inside the text area. Well, at least that's what happened in WAMP. Never tried anything on a web server.
 
Even that would have worked Dan .
Just add that to echo .

PHP:
<?
echo "<textarea>".file_get_contents("robots.txt")."</textarea>";
?>

And like Mentok says , its so much easier :)
 
Make sure you've got a .php (or PHP enabled) page... and php is installed on the server. That's the only reason why I would think it'd just display the actual code instead.

With WAMP - are you accessing it via C:\path\to\wamp\project\script.php or http://localhost/project/script.php ?

The latter will work. The former won't.
 
Back
Top