I'm not sure what I'm doing wrong but I'm getting the right nodeValue for what I want. It's just not updating when the php script is done. Here's the code:

我不确定我做错了什么但是我得到了正确的nodeValue以满足我的需求。它只是在php脚本完成时没有更新。这是代码:

    $dom = new DOMDocument();
    //suppress HTML5 and other errors
    libxml_use_internal_errors(true);
    $dom->loadHTMLFile($pageURL);
    libxml_use_internal_errors(false);
    $xpath = new DOMXPath($dom);
    $divContent = $xpath->query("//*[@id='resultStats']/p")->item(0);
    $newText = new DOMText("100 results");
    var_dump($divContent->nodeValue); //returns old test value "400 results" which is correct
    $divContent->removeChild($divContent->firstChild);
    $divContent->appendChild($newText);
    var_dump($divContent->localName); //"p" because i got it from <p> in resultStats
    var_dump($divContent->textContent); //"100 results"
    var_dump($divContent->nodeValue); //"100 results"

more of the HTML that is around it

更多围绕它的HTML

    <div class="container">
    <div class="row">
    <div class="resultStats span3 offset1" id="resultStats">
      <p>400 results found.</p>
    </div>
    </div>
    <div class="row">
     <div class="span12">
         <div class="row">
              <div class="span6 offset1">
                  <?php
                         if (isset($_POST['q'])) {
                        //code from above that is executing every time from tests
                         }
                  ?>
               </div>
               <div class="span5">
                  span5
                  </div>
                  </div>
                  </div>
                  </div>

I'm not sure what I'm doing wrong. If I do dom->save it rewrites everything (even php code) so I don't think that's a good idea.

我不确定我做错了什么。如果我做dom->保存它会重写所有内容(甚至PHP代码),所以我认为这不是一个好主意。

1 个解决方案

#1


0

I don't understand why you're using DOMDocument for this. Can't you just do this:

我不明白你为什么要使用DOMDocument。你不能这样做:

<div class="container">
<div class="row">
<div class="resultStats span3 offset1" id="resultStats">

<?php

  // get new result count somehow in $resultCount

  echo '<p>'.$resultCount.' results found</p>';
?>
</div>
</div>

更多相关文章

  1. 几个有用的php字符串过滤,转换函数代码
  2. PHP的$ _GET和URL重写
  3. 在Web Page中包含PHP代码
  4. php mail函数一段好的代码
  5. 用于上传多个文件的PHP代码
  6. (phpQuery)对网站产品信息采集代码的优化
  7. 韩顺平_php从入门到精通_视频教程_学习笔记_源代码图解_PPT文档
  8. 【MySQL 技巧分享】 mysql -e 加 v 简化代码
  9. Oracle相当于MySQL代码“插入虚拟”以返回错误消息

随机推荐

  1. 基于Spring Security Oauth2的SSO单点登
  2. Spring Job?Quartz?XXL-Job?年轻人才做选择,
  3. jQuery 3D焦点图动画,多种炫酷图片切换特
  4. 「webpack 核心特性」loader
  5. CSS3 3D旋转下拉菜单
  6. Apollo 源码解析 —— 服务自身配置 Serv
  7. Apollo 源码解析 —— Config Service 记
  8. 用JavaScript实现二叉搜索树[每日前端夜
  9. 从.env文件中为NodeJS加载环境变量[每日
  10. Apollo 源码解析 —— Portal 创建灰度