FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » DOMDocument HTML problem
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: DOMDocument HTML problem [message #177106 is a reply to message #177104] Tue, 21 February 2012 20:08 Go to previous message
Aaron Gray is currently offline  Aaron Gray
Messages: 4
Registered: August 2011
Karma:
Junior Member
"Aaron Gray" wrote in message news:9qi7vtFfmvU1(at)mid(dot)individual(dot)net...

Hi, I am trying to take an incomplete "summary" of a number of characters
of an HTML fragment without DOCTYPE, HTML, or BODY elements and a possibly
incomplete unbalanced fragment, and convert it to a ballanced fragment
without DOCTYPE, HTML, or BODY, using DOMDocument and friends.

~~~
<?php

$html = '<div><div><span>
<p><a href="#test">foo</a></p>
<hr>
<br>
<span>name</span>
';

$html = trim( preg_replace( '/\s\s+/', '', $html));

echo $html . "\n\n";

$dom= new DOMDocument();
$dom->loadHTML($html);

$xpath = new DOMXPath($dom);

$body = $xpath->query('/html/body/*');

echo $dom->saveXml($body->item(0));

?>
~~~

This does the job !

Aaron
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: FILTER_SANITIZE_NUMBER_FLOAT non/sense
Next Topic: jailshell and PHP daemon
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 18:02:48 GMT 2024

Total time taken to generate the page: 0.05256 seconds