Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Thu Feb 16, 2006 4:47 pm
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.....
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Thu Feb 16, 2006 4:49 pm
Do a search for xml to array there are a couple good classes out there to help
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Fri Feb 17, 2006 6:13 pm
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]);