Solved

DomDocument -> outputting saveHTML()

Posted on 2014-10-16
1
94 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

867 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

16 Experts available now in Live!

Get 1:1 Help Now