Can PHP include work for only a specified portion of a file?(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());
这篇关于PHP 可以仅包含文件的指定部分的工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP 可以仅包含文件的指定部分的工作吗?


基础教程推荐
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在多维数组中查找最大值 2021-01-01