regex - Preg_match extract text between <a> and </a> -


i have in code that:

<a href="http://www.allegro.pl/show_item.php?item=3069353216" target="_blank">buty trekkingowe chiruca tasmania 12 gtx roz. 44</a>  

now want extract it: buty trekkingowe chiruca tasmania 12 gtx roz. 44

im geting data imap (using php). varible item code different each data extracted hasto respect numeric values there

can me put preg_match it?

an example domdocument:

$html = '<a href="http://www.allegro.pl/show_item.php?item=3069353216" target="_blank">buty trekkingowe chiruca tasmania 12 gtx roz. 44</a>'; $dom = new domdocument(); @$dom->loadhtml($html);  $number = '3069353216';  $anodes = $dom->getelementsbytagname('a');  foreach ($anodes $anode) {     if (preg_match('~=' . $number . '$~', $anode->getattribute('href')))         echo $anode->nodevalue; } 

if want checks several numbers , since $number part of regex pattern, can write:

$number = '(?:3069353216|30804254251)'; 

or can generate array:

$numbers = array('3069353216', '30804254251', ...); $number = '(?:' . implode('|', $numbers) . ')'; 

if don't need specific number: $number = '[0-9]+';

if don't need number, can remove if (preg_match...


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -