Page 1 of 1

Echoing an HTML document

Posted: Wed Aug 08, 2007 10:52 pm
by blackcow
This seems like a simple thing, so simple that I couldn't find anything through google or w3c.

I am fairly new to PHP but I used what I know and it worked except for a strange problem, at the end of the echoed file it put the number 1, I have no clue why its doing this. I checked the HTML document and it didn't have the number one at the end so its the PHP doing it.

My code,

Code: Select all

<?php
$links = require_once('links.html');
echo "$links"
?>
At first I tried echoing "links.html" and it worked except it spit out the word "links.html" at the end, now it seems to want to spit out 1.

Is there a better way of doing this?

Posted: Wed Aug 08, 2007 11:00 pm
by iknownothing
"require_once" is essentially echoing the file anyway, so replace:

Code: Select all

<?php
$links = require_once('links.html');
echo "$links"
?>
with...

Code: Select all

<?php
require_once('links.html');
?>
Also, you didn't have a semicolon at the end of the echo line...

Posted: Wed Aug 08, 2007 11:04 pm
by feyd
There shouldn't be any PHP code in links.html. There isn't any, right? Then require() isn't optimal. readfile() would be better in that case.

If there's PHP in the file, make sure .html is parsed by PHP, or the code contained is independent and nondestructive, then require() is fine..

Posted: Wed Aug 08, 2007 11:37 pm
by blackcow
iknownothing wrote:"require_once" is essentially echoing the file anyway, so replace:

Code: Select all

<?php
$links = require_once('links.html');
echo "$links"
?>
with...

Code: Select all

<?php
require_once('links.html');
?>
Also, you didn't have a semicolon at the end of the echo line...
Ah excellent, worked perfectly. Thank you.