Solved

DomDocument -> outputting saveHTML()

Posted on 2014-10-16
1
92 Views
Last Modified: 2014-10-17
Hi all,

So i have just wrote some code that changes and images to text within the html shown below:

      
$movement =  $article->childNodes->item(12)->ownerDocument->saveHTML($article->childNodes->item(12))."<br />";	
					@$dom3->loadHTML($movement);
					 $xpath5 = new DOMXPath($dom3);
					foreach($xpath5->query('//img[contains(@src, "blue")]') as $link) {
    $link->parentNode->replaceChild($dom3->createTextNode(" > "), $link);
}
					foreach($xpath5->query('//img[contains(@src, "red")]') as $link) {
    $link->parentNode->replaceChild($dom3->createTextNode(" < "), $link);
}
			echo $dom3->saveHTML();

Open in new window


so an example of this would be

before
<td class="winner betting-movement">
                11/8<img src="/images/site/blue-arrow-small.gif" width="6" height="11">6/4          </td>

Open in new window


after

<html><body><td class="winner betting-movement">
                11/8 &gt; 6/4           </td><br></body></html>

Open in new window



what i would like to do now is go from this echo $dom3->saveHTML(); to just showing the text e.g " 11/8 &gt; 6/4  "

i thought something like this would do it but i stand corrected echo $dom3->saveHTML()->textContent;
0
Comment
Question by:runnerjp2005
1 Comment
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
Comment Utility
Try this

<?php

// Set up some test data
//
$data = <<<DOC
<html><body><td class="winner betting-movement">
                11/8 &gt; 6/4           </td><br></body></html>

DOC;



// Strip out the content
//
$text = 'Nothing found';

if ( preg_match( '#.*?<td[^>]+>([^<]+).*#is', $data, $match ) )
     $text = trim( $match[1] );


echo "Got '$text'";

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
spacing 5 25
CSS grid style change 2 13
Bootstrap css to change alignment without using padding 3 25
Bootstrap 3 icons 3 0
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now