php - Preserve line breaks between images in DomDocument -


consider php code:

$content = '<img />'."\n\n".'<img />'; $doc = new domdocument(); $doc->loadhtml($content); echo $doc->savehtml(); 

the output (including wrapping html/body etc) gives me:

<img><img> 

with no space between images.

calling:

$doc->preservewhitespace = true; 

doesn't change anything.

how preserve white space in original html?

answering own question - it's buggy behaviour of old version of libxml2:

https://bugs.php.net/bug.php?id=50278

this issue solved passing libxml_html_nodefdtd option when loading document. constant available of php 5.4.0 when libxml2 >= 2.7.8 used. see http://3v4l.org/qs4tc.

the shared server i'm on uses 2.7.6 not sure helps me, can see if can upgrade. hope helps else.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -