Solved

DomDocument -> outputting saveHTML()

Posted on 2014-10-16
1
100 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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?
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
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…

622 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