0

I am trying to loop through a series of p tags on a source page. Within each p tag there will be formatted text, e.g. <p>hello, my name is <b>bob</b></p>

I would like to each hello, my name is <b>bob</b> but am currently only getting hello, my name is bob without the <b> tags.

I assume nodeValue is not the correct call but unsure what to use

$xpath = new DOMXPath($doc);
$row = $xpath->query('//div[@class="article-body"]/p');

foreach($row as $r) {
  echo $r->nodeValue;
}
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Chris
  • 4,672
  • 13
  • 52
  • 93
  • nodeValue is basically "innerText" - any text nodes, WITHOUT html tags. you want innerHTML instead, hence the dupe – Marc B Feb 23 '16 at 14:25
  • I appreciate the reply. Whilst echo $r->nodeValue; works if I use echo $r->innerHTML I get nothing output ? – Chris Feb 23 '16 at 14:44

0 Answers0