Page 1 of 1

[SOLVED] Problem Displaying PHP Code

Posted: Sun Jun 20, 2004 6:06 pm
by Deemo
Hello guys :)

Here is my problem. I am making an application that is esentially like a remote file manager. This program works fine accessing html files, but i get many errors while reading php files. here is my code:

Code: Select all

<?php
$handle = fopen($Page, "r");
		$lines = fread($handle, filesize($Page));

		echo '<form action="admin.php?page=$Page&act=up" method="post">
		<textarea rows="25" cols="100" name="html">$lines</textarea><input type="submit" value="Edit HTML">
		</form>';
?>
The Problem is that when a php file is loaded up, i get a garbled up mess. What i think is being done is the php code is actually being evaluated. How do i make it so that none of the php code is read, it is just outputted to the textarea element?

Thanks
Deemo

Posted: Sun Jun 20, 2004 6:20 pm
by markl999
PHP variables don't get interpolated (evaluated) inside single quotes, so:

Code: Select all

echo '<form action="admin.php?page=$Page&act=up" method="post">
      <textarea rows="25" cols="100" name="html">$lines</textarea><input type="submit" value="Edit HTML">
      </form>';
wouldn't be right, it would need to be something like:

Code: Select all

echo '<form action="admin.php?page='.$Page.'&act=up" method="post">
      <textarea rows="25" cols="100" name="html">'.$lines.'</textarea><input type="submit" value="Edit HTML">
      </form>';
But apart from that, it shouldn't be evaluating the fopen'd php code and i can't see a reason why it would do :o

Posted: Sun Jun 20, 2004 6:39 pm
by feyd
how about this

Code: Select all

<?php

if(is_readable($Page))
{
  $lines = htmlentities(file_get_contents($Page),ENT_QUOTES);
  echo "<form action="admin.php?page={$Page}&act=up" method="post"><textarea rows="25" cols="100" name="html">{$lines}</textarea><input type="submit" value="Edit HTML"></form>";
}
else
  die($Page.' cannot be read.');

?>

Posted: Sun Jun 20, 2004 6:55 pm
by Deemo
thank You very much feyd, that worked

@ mark: I accidently put it in single quotes cuz i copyed and pasted a trial that i did to make it work. d'oh

Posted: Sun Jun 20, 2004 7:00 pm
by John Cartwright
Sorry to go offtopic but:

Demo: Your sig i disagree with :)

semi-noobs best friend?

everytime I'm coding I always have my manual out with me... I can guarantee a lot of advanced users do aswell :)

Posted: Sun Jun 20, 2004 8:01 pm
by Deemo
how about semi n00b and up lol

yeah i use that site more than anything