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

Home » Imported messages » comp.lang.php » String Replacement
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: String Replacement [message #172230 is a reply to message #172225] Mon, 07 February 2011 08:17 Go to previous messageGo to previous message
Pavel Lepin is currently offline  Pavel Lepin
Messages: 1
Registered: February 2011
Karma:
Junior Member
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PHP server tag help
Next Topic: An extremely large hash lookup mechanism
Goto Forum:
  

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

Current Time: Sun Nov 10 17:03:29 GMT 2024

Total time taken to generate the page: 0.04528 seconds