Forum Moderators: coopster

Message Too Old, No Replies

regex to fetch data between two tags

everything seems to be right but still not working

         

phparion

6:14 am on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi

I am applying regex on a page to fetch out data between <address></address> tags and facing few problems

this is what I am using currently

preg_match_all("/<address[^>]*>(.*?)<\/address>/",$content,$output3);

but I am getting empty array in return

Array
(
[0] => Array
(
)

[1] => Array
(
)

)

I also tried the following

preg_match_all("/<address>.*?<\/address>/",$content,$output3);

but it also gives empty result.

I wonder if anyone could shed some light that what am I doing wrong here?

thank you

phparion

7:12 am on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



just a quick thought the address tags have data like

stree#, blah blah<br />
city, state<br />
country, zipcode....

I am not sure that (.*) is good enough to read all of this or should i use a character class with [] and put every possible type of character in it?

phparion

8:46 am on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



after banging my head with regex for hours i have finally solved it with the following one, wanted to mention here so if any other mate need it in future...

preg_match_all("/<address>[\/\(\)-:<>\w\s]+<\/address>/",$cnt,$mat);

btw if I use this

preg_match_all("^<address>[\/\(\)-:<>\w\s]+<\/address>$",$cnt,$mat);

i get delimiter error... why is that? because i guess ^$ are used for start and end of the pattern...

d40sithui

11:19 am on Aug 29, 2007 (gmt 0)

10+ Year Member



i think when you use preg_match you need to have to start and end with the "/". if you use eregi or something, you will not need "/". good job btw!