Loading an HTML page

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
mavedog21
Forum Newbie
Posts: 23
Joined: Thu Dec 21, 2006 1:27 pm

Loading an HTML page

Post by mavedog21 »

Hello,

I can't seem to load an html page.

I know this is probably the most basic question but I can't seem to
find a tutorial or instructions besides the php.net's loadHTMLFile
which seems to throw up a bunch of errors.

I test at home using php5 so I can't test until later but here is
what I've already tried, it's in an if statment

php5 code snippet

Code: Select all

if(!empty($myVariable)){
    $doc = new DOMDocument();
    $doc->loadHTMLFile("filename.html");
             echo $doc->saveHTML();
}else{
     $doc = new DOMDocument();
     $doc->loadHTMLFile("filename.html");
   echo $doc->saveHTML();
}
This throws up errors and then the HMTL page requested underneth the errors.
I can't remember what exactly the errors are because I'm at work but I'm curious if I'm even on the right track?

Should I be using fopen which didn't seem to work either.

If you have some quidance or know of a script online I can look at that would be cool.

thanks, sorry it's kinda vague I'm at work trying to figure this out on my down time.

sky
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

What errors?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

If you're looking for any solution, you could use file_get_contents()

Code: Select all

echo file_get_contents('page.html');
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
mavedog21
Forum Newbie
Posts: 23
Joined: Thu Dec 21, 2006 1:27 pm

Post by mavedog21 »

For reasons I don't know it justed started working without any problems.
The same code I tried before just started working. I have no clue why.

thanks for the other option scottayy.

sky
Post Reply