xml stuff

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

xml stuff

Post by shiznatix »

Well ok its not really XML its just some my own tags in a txt document. Here is what I have

Code: Select all

<title>title</title>
<short>short</short>
<long>whole</long>
I need to get 'title' into 1 variable, 'short' into another, and 'whole' into a third. I searched for some html regex here but I did not understand any of it. Some help please.....
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Do a search for xml to array there are a couple good classes out there to help :)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

http://us3.php.net/simplexml

This works with valid XML documents
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

untested...but probably should work...

Code: Select all

$input =<<<EOT
<title>title</title> 
<short>short</short> 
<long>whole</long> 
EOT;
preg_matches("#<title>(.*?)</title>#i", $inputString, $matches);
$titleString = implode("", $matches[1]);
preg_matches("#<short>(.*?)</short>#i", $inputString, $matches);
$shortString = implode("", $matches[1]);
preg_matches("#<long>(.*?)</long>#i", $inputString, $matches);
$longString = implode("", $matches[1]);
Post Reply