PHP是否只包含文件的指定部分? [英] Can PHP include work for only a specified portion of a file?
本文介绍了PHP是否只包含文件的指定部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个PHP include,它将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>
所以include会进入那个包含表单的文件并获取指定的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);
或者,作为oneliner:
Or, as a oneliner:
print form_tag_wrapper(form_contents());
这篇关于PHP是否只包含文件的指定部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文