Nuv Posted March 16, 2011 Share Posted March 16, 2011 I am trying to capture the href link from one of the sites.The part of the source code is as follows <tr bgcolor="#CCCCCC"> <td align=right></td> <td align=center valign=center width=10><a href="/info/link1"> I am using preg_match_all('~<tr\sbgcolor="#CCCCCC">\s<td\salign=right></td>\s<td\salign=center\svalign=center\swidth=10><a\shref="(.*)">\siU~', $data, $link); However $link isn't storing anything. Is my regex right ? Link to comment https://forums.phpfreaks.com/topic/230774-is-my-regex-right-trying-to-capture-the-link/ Share on other sites More sharing options...
sasa Posted March 16, 2011 Share Posted March 16, 2011 preg_match_all('~<tr\sbgcolor="#CCCCCC">\s*<td\salign=right></td>\s*<td\salign=center\svalign=center\swidth=10><a\shref="(.*?)">~siU', $data, $link); Link to comment https://forums.phpfreaks.com/topic/230774-is-my-regex-right-trying-to-capture-the-link/#findComment-1188049 Share on other sites More sharing options...
Nuv Posted March 16, 2011 Author Share Posted March 16, 2011 Added + after ever \s to make it something like <a\s+href="(.*?)"> and it worked. Link to comment https://forums.phpfreaks.com/topic/230774-is-my-regex-right-trying-to-capture-the-link/#findComment-1188051 Share on other sites More sharing options...
Nuv Posted March 16, 2011 Author Share Posted March 16, 2011 Thankyou sasa. I figured that out after reading couple of sites. Link to comment https://forums.phpfreaks.com/topic/230774-is-my-regex-right-trying-to-capture-the-link/#findComment-1188052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.