Harish Ninge Gowda
Harish Ninge Gowda

Reputation: 441

Read php source from another php script

I have two files reader.php and somesource.php. Both in the same folder.

somesource.php content inside the php tag.

echo "hello World";

reader.php contents

$fp = fopen('somesource.php','r') or die($php_errormsg);
$string = fread($fp,filesize('somesource.php'));
echo $string."<br>";

I am expecting to output

echo "hello World";

But I am seeing a blank page. I even tried. curl and file_get_contents. Both with the same output. If I write anything outside the php tag wil be echoed as normal. anything inside the php tag is skipped.

Please Help

Upvotes: 1

Views: 90

Answers (2)

Umesh M Gowda
Umesh M Gowda

Reputation: 121

use

echo htmlspecialchars($string)."<br>";

Upvotes: 1

brs14ku
brs14ku

Reputation: 346

Depending on your server setup it may not read it without <?php echo $stuff; ?> in there. <? aka short tags can break a lot of stuff in my experience.

Upvotes: 0

Related Questions