I'm writing a wee link extractor and it works fine for text links but I need it to handle links behind images. I've got this code if (eregi( ".*<IMG.*ALT=\"(.*)\".*>.*", $link, $out)) { $curLink['title'] = $out[1]; } PHP: but it picks up everthing from the alt tag to the last " for example this image <img alt="Fort Knox in a Box. Visit Lenovo to learn more." src="/us/images/2005/10/102505_T7_Lenovo_Vault.gif" width="152" height="60" border="0" /> Code (markup): returns Fort Knox in a Box. Visit Lenovo to learn more." src="/us/images/2005/10/102505_T7_Lenovo_Vault.gif" width="152" height="60" border="0 Code (markup): when it should return Fort Knox in a Box. Visit Lenovo to learn more. Code (markup): Any ideas on how to get the regular expression to behave?
a " sign cannot exist in a ALT="" tag, should be a " sign, so changing your regexp (.*) to ([^\"]*) will probably fix it. if (eregi( ".*<IMG.*ALT=\"([^\"]*)\".*>.*", $link, $out)) { $curLink['title'] = $out[1]; }