Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #11032
| Path | csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!weretis.net!feeder3.news.weretis.net!news.solani.org!not-for-mail |
|---|---|
| From | Pavel Lepin <p.lepin@dyninno.com> |
| Newsgroups | comp.lang.php |
| Subject | Re: String Replacement |
| Date | Mon, 07 Feb 2011 10:17:32 +0200 |
| Organization | solani.org |
| Lines | 40 |
| Message-ID | <iio9qs$nnu$1@solani.org> (permalink) |
| References | <05c6ea05-cabb-41b7-9f9b-68587327e210@f2g2000yqf.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | solani.org 1297066652 24318 eJwNwokRwDAIA7CVAPPME+Nk/xHakwrtvZNdnfV+6RgfAiySY2cR55pswcg0yVKl6+v1Qh8T7REw (7 Feb 2011 08:17:32 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Mon, 7 Feb 2011 08:17:32 +0000 (UTC) |
| X-User-ID | eJwFwQcBACAIBMBKKEviPKt/BO+U7Vi5mJro6oLxeG5yTSY59iGnIk50gUwkWm+7JKYujD47IxIR |
| Cancel-Lock | sha1:ziDwH/yP3GhA8QJ8susMr1PcWHs= |
| User-Agent | KNode/0.10.9 |
| X-NNTP-Posting-Host | eJwFwYEBwDAEBMCVSt6HcRD2H6F3dijsCxphayvOao1Jm/FnkuLFSuxD45NwxmD0NLJU7/sBJwYRYA== |
| Xref | csiph.com comp.lang.php:11032 |
Show key headers only | View raw
Alec wrote:
> I am not sure where to start on this on.
Read up on XML processing.
> I have a string as follows '<text
> identifier="3ecebe84-8ddd-475e-86ca-300b5298fc34">
> <value><![CDATA[12345]]></value>'
>
> The text identifier always remains the same ie. 3ece..... for each
> article. The string is much longer containing several different
> identifiers. I would like to be able to jump to the one shown, and
> then extract the CDATA value shown after ie. 12345. The length of this
> may change, so I need a way to extract the text between the second '['
> and first ']' . I hope that makes sense.
Assuming your actual data is well-formed XML (the above snippet is not):
<?php
$dom = new DOMDocument;
$dom->loadXML($string);
$xpath = new DOMXpath($dom);
$query = '/text[starts-with(@identifier, \'3ece\')]/value/text()';
$nodelist = $xpath->evaluate($query);
if ($nodelist->length === 1)
{
print($nodelist->item(0)->nodeValue."\n");
}
else
{
die('invalid query result: '.
'['.strval($nodelist->length).'] nodes returned'."\n");
}
?>
--
Pavel Lepin
Back to comp.lang.php | Previous | Next — Next in thread | Find similar | Unroll thread
Re: String Replacement Pavel Lepin <p.lepin@dyninno.com> - 2011-02-07 10:17 +0200 Re: String Replacement Alec <ajtdds@aol.com> - 2011-02-07 22:39 -0800
csiph-web