2

所以我有两个文件,一个是 index.php,另一个是march.html,我想从march.html 中获取员工的名字,我设置了一个id

<h3 id="name">John Doe</h3>

那么我将如何从march.html 中获取该名称,以便将其放在我的index.php 中。如果您想要更多详细信息,就像本月最佳员工一样,我需要从其他 11 个文件中获取名称,以便在 index.php 中引用它们。我试过在 php 中使用 DomDocument 但它显示了很多麻烦但这里是代码只是因为

<?php
      $dom = new DomDocument();
      $dom->validateOnParse = true;
      $dom->loadHtml("march.html");
      $name = $dom->getElementById("name");
      print $name;
?>
4

2 回答 2

4

使用 nodeValue 属性获取值:

<?php
      $dom = new DOMDocument();
      $dom->validateOnParse = true;
      $dom->loadHTML(file_get_contents("march.html"));
      $name = $dom->getElementById("name")->nodeValue;
      print $name;
?>
于 2013-06-07T17:37:35.177 回答
1

我会使用 jQuery AJAX 调用来使用专门的 ajax 函数“加载”

例子:

$('#result').load('ajax/test.html #container');

jQuery 加载 API: http ://api.jquery.com/load/

于 2013-06-07T17:38:39.747 回答