0

Can you with "php simple html dom" take a piece of HTML and NOT only the content?

I have trie with:

foreach ($html->find('div.info-bar') as $infop) {
  $info = $infop->plaintext;
}

Unfortunately, the output is:

Level 24 Trophies 4201 Bronze 2725 Silver 1057 Gold 341 Platinum 78 Level 24 66 66 %

While I would like to extract the pure HTML..

This is my code:

include('simple_html_dom.php');
$html = file_get_html('https://my.playstation.com/obaidmiz04');
foreach ($html->find('div.info-bar') as $infop) {
  $info = $infop->plaintext;
}
echo $info;
2
  • you probably want to add the string to the $info variable, not overwriting it. So use .= instead of = in the loop. Commented Sep 25, 2016 at 16:21
  • I tried, but continues to print only the text and not the html... Commented Sep 25, 2016 at 16:28

1 Answer 1

1
$escapedHtmlChars = "";
$htmlElements = "";
$html = file_get_html('https://my.playstation.com/obaidmiz04');
foreach ($html->find('div.info-bar') as $infop) {
  //You can see html characters in text
  //This shows you html codes, not for using
  $escapedHtmlChars .= htmlspecialchars($infop); 
  //You can see html elements
  $htmlElements .= $infop;
  //You can see only text in selected element
  $plainText .= $infop->plaintext;
}
echo $plainText;
echo "<br /> <br />";
echo $escapedHtmlChars;
echo "<br /> <br />";
echo $htmlElements;

plaintext method returns only text in selected element.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.