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?!
If you want to just put the HTML into a string, you can just use:
$file1 = file_get_contents("file.html");
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.
To store:
$contents = file_get_contents('example.html');
To output:
readfile('example.html');
精彩评论