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

Home » Imported messages » comp.lang.php » Re: DOM and node
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Re: DOM and node [message #173851] Tue, 10 May 2011 14:23
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 10/05/2011 13:48, smerf escribió/wrote:
> I have XML like this :
>
> <li>
> Producer:
> <strong>
> <a href="link.html">Name</a>
> </strong>
> </li>
>
>
> How to get only "Producer:" without value of <strong> node ?
>
> I would like to do it in a preety way using built-in PHP classes of DOM
> family.
>
> I can't find solution better then :
> $nodeLI->nodeValue and REGEX
>
> How do you process XML like this one?

If the structure won't change, you can do this:

<?php

$xml_string = '<?xml version="1.0" encoding="ISO-8859-1"?>
<li>
Producer:
<strong>
<a href="link.html">Name</a>
</strong>
</li>';

$doc = new DOMDocument;
libxml_use_internal_errors(TRUE);
$doc->loadXML($xml_string);
libxml_use_internal_errors(FALSE);

$lists = $doc->getElementsByTagName('li');
foreach($lists as $li){
var_dump($li->firstChild->nodeValue);
}

You can trim() the value if you wish.



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: PHP Document
Goto Forum:
  

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

Current Time: Fri Nov 22 20:42:58 GMT 2024

Total time taken to generate the page: 0.02581 seconds