Hi, I would like to extract from a string the value of all <A HREF> nodes that contain the text ".MBR". Can anyone suggest how to do this? Example -------- String is: $str = "<A HREF=/location/$file/filename.MBR> <font size="1" face="Arial> <A HREF=/location/$file/filename.htm><A HREF=/location/$file/filename2.MBR>"; Desired result is: "/location/$file/filename.MBR" and "/location/$file/filename2.MBR" I think that preg_match_all and preg_replace are probably the way to do this, but I don't know what the syntax for the patterns should be? Is there are good resource for describing the syntax of patterns? Thanks in advance, Ade
preg_match_all('~\s+href=["\']?(.+\.MBR)["\'>]~si', $text, $matches); print_r($matches[1]); PHP: Untested but should work.
Thanks for your response nico_swd. I tried your suggestion and the result was: Array ( [0] => /location/$file/filename.MBR> <font size="1" face="Arial> <A HREF=/location/$file/filename.htm><A HREF=/location/$file/filename2.MBR ) Any idea how I can get the following result in an array?: "/location/$file/filename.MBR" and "/location/$file/filename2.MBR"
$str = '<A HREF=/location/$file/filename.MBR> <font size="1" face="Arial> <A HREF=/location/$file/filename.htm><A HREF=/location/$file/filename2.MBR>'; //Match all links preg_match_all('/<a href=(.*)>/Uis',$str,$results); /* or only match MBR preg_match_all('/<a href=(.*\.MBR)>/Uis',$str,$results); */ print_r($results[1]); PHP: Peace,