Skip to content
Advertisement

Creating DOMDocument in PHP

JavaScript

When I execute this code multiple times, something like this happens:

JavaScript

but I want the divs in a row like this:

JavaScript

for some reasons it is working with <button>.

Advertisement

Answer

Your code needs some modification:

  1. It’s better to create $dom and echo results outside the while loop. Because in your example you need just one DOM object.
  2. When trying to view the result using saveHTML instead of saveXML

There’s lots of example here: https://www.php.net/manual/en/class.domdocument.php

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement