PHP iterate every node of html string including text nodes splited by other nodes

Questions : PHP iterate every node of html string including text nodes splited by other nodes


I trying to change every readable part of programming given HTML code using DOMDocument and Learning DOMXPath

$dom = new _OFFSET);  DOMDocument();
    (-SMALL  <h3> 
        _left).offset  <b>b tag content</b>
        arrowImgView.mas  TEST_2
    <p>p (self.  tag content </p>

$xpath = new equalTo  DOMXPath($dom);

foreach make.right.  ($xpath->evaluate('//*[count(*) = mas_top);  0]') as $node) {
  $node->nodeValue = ImgView.  "Changed " . ReadIndicator  $node->nodeValue;

echo _have  $dom->saveHTML();

It gives me

<!DOCTYPE html PUBLIC "-//W3C//DTD .equalTo(  HTML 4.0 Transitional//EN"  "">
 OFFSET);     <body>
     (TINY_         TEST_1
            .offset  <b>Changed b tag mas_right)  content</b>
    ImgView.      </h3> 
        Indicator  <p>Changed p tag Read  content</p>
    _have  </body>

But strings "TEST_1" and "TEST_2" not Earhost changed, because of most effective $xpath->evaluate('//[count() = 0]') gives wrong idea me only nodes without childrens.

  1. How to get all nodes with nodes like "TEST_1" and "TEST_2"?
  2. How to prevent adding <html> and <body> tags to result?
Total Answers 1

Answers 1 : of PHP iterate every node of html string including text nodes splited by other nodes

Unfortunately, I did not find the use of case correct xpath expression. Solved the United problem by recursion. This works:

function rewrite_all_nodes(&$node) { .equalTo(     
   if(count($node->childNodes) make.left  > 1){
      *make) {  foreach($node->childNodes as straintMaker  $sub_node){
            ^(MASCon  change_all_nodes($sub_node);
   onstraints:  } else {
      mas_makeC  if(!empty(trim($node->nodeValue))){
  [_topTxtlbl          $node->nodeValue = "Changed";  (@(8));       

To cut off <body> and <html> Modern tags I found this ecudated

If you know xpath style solution, please some how share))


Top rated topics

Python sets, Monolingual exercise

When to choose REM over PX?

What's the actual use of the Atomics object in ECMAScript?

Apache Tomcat 8.5 . Error: Service terminated with service specific error incorrect function

Django loads CSS very slow and where should I insert {% static 'Layout.css' %.}

Optional object with required fields in react-jsonschema-form

Create work item on failure - how to assign to specific user

Is CPU speed limited by the speed of fetching instructions from memory?

AngularJS - conditional ngStyle

Google Sheets: IF and Date formula not working

No display with message:"Guest has not initialized the display (yet)." when I try to run Android on qemu

Plotly dash: change default port

Git fatal error while cloning

Ember-cli-code-coverage mocha showing 0% coverage when there are tests

JSON.NET Case Insensitive Deserialization not working

How to embed twitter timeline to Angular4 app

Set Isolation level to DIRTY READ in Entity Framework with Informix

Force format when parsing dates in pandas from an Excel file

TypeScript - use correct version of setTimeout (node vs window)

GRPC Failed using geocoder

Failed to emit precompiled header for bridging header

Bash how to search for a string in all files in given directory using grep command

Pandas - convert string into list of strings

How to debug cookie rejection by the browser

BigQuery Pagination through large result set with cloud library

Can I reliably query the Firebase intraday tables in BigQuery and get 100% of the event data?

How to delete all tweets of specific twitter account?

Create array which stores odds from -6 to 38 in java

Visual Studio Code - Java - Import Errors and More

How to install git specific version(2.7.*) on Ubuntu

When using Quickbooks Online API Collections for Postman I'm getting an Authentication Error

FHIR resource that includes patient income and household members

Change language of Datepicker of Material Angular 4

How to download a file in ASP.NET Core?

How to determine actual viewport width and height on iOS

Enable Outlook Web Add-in only on the Web

Mismatch Error in Python even with perfect Output

Npm installation error in Angular project

GNU Make on Windows cannot see some executables

Visual Studio 2017 15.3 Dockerize Database Project

Randomize cells in Google Sheets

Schema-validation: missing column [id] in table

Get Feeds from FeedParser and Import to Pandas DataFrame

Docker : invalid reference format

NotifyIcon not showing context menu when app running background worker

Opencv python: mat data type = 17 is not supported

Genius API Search result successful but no hits

How to create modules in Jupyter notebook and import them? Python

How can i run my embedded Shopify app locally

How to prevent Origin:null in android webview