note 80171 added to ref.simplexml
| From: | tom at canobe dot com | Date: | Wed, 02 Jan 2008 20:46:41 +0000 |
| Subject: | note 80171 added to ref.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-134664@lists.php.net to get a copy of this message | ||
The earlier poster is right in that simplexml becomes pretty useless when you have mixed-content
XML. This means that you basically cant use simplexml for (X)HTML, which is a bit of a blow.
Here's a potential solution (hack) for those of you just finding out the mixed-content problem
and not wanting to rewrite using DOM. This probably only really works if you have well-formed xhtml,
which in my case I have from running some html through Tidy beforehand.
Before passing to simplexml, run a couple of regexs on the html to put all the mixed content inside
<span>s. This gets handled as separate elements in the tree.
// put all text content inside a <span> because simplexmlelement
// doesnt handle mixed content.
// lesson learnt: dont use simplexmlelement for html
$html = preg_replace('|>\s*<|','><',$html);
$html =
preg_replace('|>\s*([^<]+)\s*|','><span>\1</span>',$html);
----
Server IP: 69.147.83.197
Probable Submitter: 79.75.215.245
----
Manual Page -- http://www.php.net/manual/en/ref.simplexml.php
Edit -- https://master.php.net/note/edit/80171
Del: integrated -- https://master.php.net/note/delete/80171/integrated
Del: useless -- https://master.php.net/note/delete/80171/useless
Del: bad code -- https://master.php.net/note/delete/80171/bad+code
Del: spam -- https://master.php.net/note/delete/80171/spam
Del: non-english -- https://master.php.net/note/delete/80171/non-english
Del: in docs -- https://master.php.net/note/delete/80171/in+docs
Del: other reasons-- https://master.php.net/note/delete/80171
Reject -- https://master.php.net/note/reject/80171
Search -- https://master.php.net/manage/user-notes.php