Search code examples
phpsimple-html-dom

Simplehtmldom repeats the extracted field previously


I would like to extract the list from this page, but every time he also repeats the previous field, creating a kind of "pyramid". Example:

You Are Nioh Obtained all trophies.

You Are Nioh A Long Journey Begins Obtained all trophies.Completed "The Man with the Guardian

You Are Nioh A Long Journey Begins They Call Him Anjin Obtained all trophies.Completed "The Man with the Guardian Spirit".Completed "Deep in the

This is my code, where am I wrong? I would need to create the kind of query so that I can execute in the database.

foreach ($html->find('li.award') as $infop) {
  $escapedHtmlChars .= htmlspecialchars($infop);
  $title  .= $infop->find('div.trophy-title', 0)->plaintext;
  echo $title;
}

Solution

  • By using the .= operator, you are appending to your string with each iteration of the loop. Just use a plain = operator instead!