Echoing an HTML document

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

Post Reply
User avatar
blackcow
Forum Newbie
Posts: 2
Joined: Wed Aug 08, 2007 10:43 pm
Location: MA, USA

Echoing an HTML document

Post 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?
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
blackcow
Forum Newbie
Posts: 2
Joined: Wed Aug 08, 2007 10:43 pm
Location: MA, USA

Post 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.
Post Reply