Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Novicane
Oct 25, 2003

functional posted:

(I would prefer a string solution to this, or something built into the PHP library, and not some big package I have to install.)

I have a string which consists of potentially bad XML.

I have a tag <mytag> which may exist in the XML multiple times.

I want to return the text contained in first instance of <mytag>, or the empty string if it doesn't exist. So in the following instance:

php:
<?
<html>
<mytag>THIS_IS_THE_STRING</mytag>
<span>aaaaaa</span>
<html>
?>
I want to yank out the string "THIS_IS_THE_STRING"

Is there something that already does this or do I have to write it myself?


From the looks of it, you are parsing HTML which in a lot of cases can be malformed. A great extension for helping with that though is Tidy as it can cleanup and repair broken elements.

SimpleXML is a nice interface but you also have the option of using the DOM interface for interacting with XML/HTML which can sometimes give a little more flexibility. I find myself using XPath a lot for pulling content out of HTML.

Adbot
ADBOT LOVES YOU

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply