Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #11032 > unrolled thread
| Started by | Pavel Lepin <p.lepin@dyninno.com> |
|---|---|
| First post | 2011-02-07 10:17 +0200 |
| Last post | 2011-02-07 22:39 -0800 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.php
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | Pavel Lepin <p.lepin@dyninno.com> |
|---|---|
| Date | 2011-02-07 10:17 +0200 |
| Subject | Re: String Replacement |
| Message-ID | <iio9qs$nnu$1@solani.org> |
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
[toc] | [next] | [standalone]
| From | Alec <ajtdds@aol.com> |
|---|---|
| Date | 2011-02-07 22:39 -0800 |
| Message-ID | <645db8cb-cfc6-4cc7-8dbd-550bc18445b3@w6g2000vbo.googlegroups.com> |
| In reply to | #11032 |
Firstly many thanks both of you for the quick reply. XML processing is new to me, but I will try to get my head around this. Alec
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web