PHP 可以仅包含文件的指定部分的工作吗? [英] Can PHP include work for only a specified portion of a file?

查看:20
本文介绍了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 可以仅包含文件的指定部分的工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆