PHP 可以仅包含文件的指定部分的工作吗?

2022-01-25 00:00:00 include php

我有一个 PHP 包含,它可以将一个 html 表单插入另一个 html 表单.包含表单后,我现在有两个表单标题.有没有我可以使用的 php 标签让我...

I have a PHP include that inserts an html form into another html form. When the form gets included I now have two form headers. Is there a php tag I could use that would allow me to...

<form id="orderform">

<!-- <?php for the include FROM here?> -->

PROD:<input class="ProductName" type="text" size="75">|
Discount:<input class="Discount" type="text" size="3">|
QTY:<input class="qty" type="text" size="6">|
Line/Total:<input class="LineTotal" type="text" size="9" disabled>

<!-- <?php for the include TO here?> -->

</form>

所以包含会进入包含表单的文件并获取指定的 HTML?

So the include would go into that file with the form in it and get the specified HTML?

这可能吗?

<?php 
$dom = new DOMDocument();
$html = 'phptest3.php';
$dom->loadHTMLFile($html);
$div = $dom->getElementById("divtagid");
echo $div->nodeValue;
?>

这仅返回文本.如何获取 divtagid 中的 HTML 表单元素?

This only returns the text. How do I get the HTML form elements in the divtagid?

推荐答案

你最好看看 php 函数.

You should best look into php functions for this.

<?php
function form_tag_wrapper($form) {
  return '<form id="orderform">'. $form .'</form>';
}

function form_contents() {
  return 'PROD:<input class="ProductName" type="text" size="75">
          ...
          Line/Total:<input class="LineTotal" type="text" size="9" disabled>';
}
?>

您将使用它作为:

$form = form_contents();
print form_tag_wrapper($form);

或者,作为单行者:

print form_tag_wrapper(form_contents());

相关文章