Nic Hubbard
Nic Hubbard

Reputation: 42173

PHP: Loading up an HTML file without it tidying my code

I am using the loadhtml function (http://php.net/manual/en/domdocument.loadhtml.phpt) to load up an external .html file. When I load it, it "tidy's" up my code, which, I don't want. I do NOT want a full HTML document, I only want html snippets in my .html, and I don't want the loadhtml file to try to make it valid html, because I don't want it to.

Is there a better function to load up a .html file so that it does not tidy up the code?!

Upvotes: 0

Views: 1035

Answers (3)

tanerkay
tanerkay

Reputation: 3930

To store:

$contents = file_get_contents('example.html');

To output:

readfile('example.html');

Upvotes: 0

Don
Don

Reputation: 4673

LoadHTML puts your html file data into a DOM structure.

If it is not really HTML (snippets aren't) then you can't really make a DOM structure -- but that is what you asked for.

Now, the first question comment asked what you wanted to do once this data was loaded, so either you have a good answer for that which will point us in a new direction, or the answer is simply NO.

Upvotes: 0

Dumb Guy
Dumb Guy

Reputation: 3446

If you want to just put the HTML into a string, you can just use:

$file1 = file_get_contents("file.html");

Upvotes: 3

Related Questions