regex help - plz
Posted 09 June 2006 - 08:12 AM
I am walking through a flatfile database trying to pull two values out. A typical line reads:
<LI><!zx1><a class=cal href=events.php?act=tit&da=4&mo=6&yr=2006&href=1149763623&q=1>link text</a>
I am after the number value &href= [eg. 1149763623] and the *link text*. There are various variations on this standard line so I need to work between the <LI> and the </a>
I have (frustratingly) tried a huge range of permutations starting with something like...
preg_match_all("#<LI>?????>(.+?)????</a>#", $line, $matches);
preg_match_all("#<LI>?????>(.+?)</a>#", $line, $matches);
I hope to find the bits to replace the ???
ANY suggestions will be much appreciated.
thanks - arfa
Posted 09 June 2006 - 03:33 PM
Don't worry, the printer fairies will sort it out.
Posted 09 June 2006 - 04:39 PM
<?php $str = '<LI><!zx1><a class=cal href=events.php?act=tit&da=4&mo=6&yr=2006&href=1149763623&q=1>link text</a>'; preg_match("/&href=([^&]+)(?:[^>]*)>([^>]*)<\/a>/", $str, $m); echo '<pre>'; echo 'HREF: ' . $m . "\n"; echo 'LINK TEXT: ' . $m . "\n\n"; print_r($m); ?>
HREF: 1149763623 LINK TEXT: link text Array (  => &href=1149763623&q=1>link text  => 1149763623  => link text )
Posted 10 June 2006 - 08:44 AM
both solutions work but...
the line provided is only typical and there are variations.
there needs to be allowance for various other text/data/lnks prior to and after the <LI>....</a>
I am trying various .?*+ permutations but this is all part of my learning curve so further guidance would be much appreciated.
Progress is being made - many thanks
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users