Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #4923
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | "Aaron Gray" <ang.usenet@gmail.com> |
| Newsgroups | comp.lang.php |
| Subject | Re: DOMDocument HTML problem |
| Date | Tue, 21 Feb 2012 20:08:05 -0000 |
| Lines | 37 |
| Message-ID | <9qibu5FgjnU1@mid.individual.net> (permalink) |
| References | <9qi7vtFfmvU1@mid.individual.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; format=flowed; charset="iso-8859-1"; reply-type=response |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net 48JBw5apFJ1tfy92o39iBgNsoxUOubsMZifMFWdcYiePL7lZFR |
| Cancel-Lock | sha1:BVhzvOWkJEJYB9jVsfWwM3jx+ek= |
| In-Reply-To | <9qi7vtFfmvU1@mid.individual.net> |
| X-Priority | 3 |
| X-MSMail-Priority | Normal |
| Importance | Normal |
| X-Newsreader | Microsoft Windows Live Mail 15.4.3538.513 |
| X-MimeOLE | Produced By Microsoft MimeOLE V15.4.3538.513 |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.php:4923 |
Show key headers only | View raw
"Aaron Gray" wrote in message news:9qi7vtFfmvU1@mid.individual.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
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
DOMDocument HTML problem "Aaron Gray" <ang.usenet@gmail.com> - 2012-02-21 19:00 +0000 Re: DOMDocument HTML problem Jerry Stuckle <jstucklex@attglobal.net> - 2012-02-21 14:14 -0500 Re: DOMDocument HTML problem "Aaron Gray" <ang.usenet@gmail.com> - 2012-02-21 20:08 +0000
csiph-web