Solved

DomDocument -> outputting saveHTML()

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

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