Solved

DomDocument -> outputting saveHTML()

Posted on 2014-10-16
1
97 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
ID: 40384739
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
HTML5 storage and web apps 11 44
Text too large in Chrome 17 56
htaccess block all countries but the US 4 34
Hta File displays dynamic File names 4 43
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

713 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