简体   繁体   中英

Dynamically adding content to HTML document using PHP

I'm trying to create some dynamic content within a HTML document which contains nested PHP code, as follows:

$html=$DOCUMENT_ROOT. "test.php";
$page=new DOMDocument();
$page->loadHTMLFile($html);
...get existing elements by ID
...create new elements
...append new elements to existing elements
$page->saveHTMLFile($html);

The code raises a whole bunch of these warnings:

DOMDocument::loadHTMLFile(): htmlParseEntityRef: no name in test.php

Furthermore, it appears that the PHP tags

< ?PHP ? >

within the source file were replaced with these:

<?php ?&gt

and thereafter the nested PHP commands are not executed but instead only displayed in the output.

I'm assuming that the PHP load/save HTML file functions are not meant for PHP files, so how could we load and save PHP files?

Thank you for your help.

Sofia

It seems, that you should include("test.php") and dynamically add the checkboxes in test.php to the form, something like this:

<?php foreach($options as $option): ?>
    <?php echo $option['label']?>: <input type="checkbox" name="<?php echo $option['name']?>" /><br />
<?php endforeach; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM