loadHTMLFile for PHP files

Hello everyone. I am trying to add some dynamic content to a page that contains PHP code. When I use the loadHTMLFile function to do this, the PHP tags <?PHP ?> are replaced by &lt?php ?&gt, corrupting it. It also raises a whole bunch of DOMDocument::loadHTMLFile(): htmlParseEntityRef: no name in… errors. All I’m trying to do is add some checkboxes to the page according to data retrieved from the database, and I believe that such action requires the use of the DOM getElementById, createElement, setAttribute and appendChild functions, which in turn requires that the page be loaded with the PHP loadHTMLFile function.

Can anyone help, please?

Thanking you,
Sofia

I haven’t heard of anyone loading a php file that way in a webserver context. Usually you name the file with a .php extension and the web server does the right thing. What web server are you using?

Hi Kiwiheretic. The PHP file works fine on the server. The problem is, after being parsed with the PHP loadHTMLFile function, the PHP function tags get corrupted. After that, the page still displays properly, but the PHP functions don’t execute because the opening and closing tags <?PHP ?> have been replaced with &lt?php ?&gt.

The page that I’m trying to load is essentially HTML content, nested with some PHP echo functions to validate form inputs; something like:
<input type=“text” … value=“<?php echo (isset($_POST[‘name’])) ? $_POST[‘name’] : ‘’; ?>”.
After being parsed by loadHTMLFile, they’re changed to:
<input type=“text” … value=“&lt?php echo (isset($_POST[‘name’])) ? $_POST[‘name’] : ‘’; ?&gt”.

I’m using the loadHTMLFile function to be able to add dynamic content to it. Unless there’s any other way to add dynamic HTML content from PHP?

Thanks again.

That function is for loading HTML not PHP.

Can’t you just include or require the file instead?

Hi felgall. If I were to use include, would I still be able to create new elements and append them to the content? I’m assuming that the included file would not be saved, so would there be a way to display the content along with the new elements?

Thank you.