php - Parse HTML links with a regular expression -
i have following code:
$regex='|<a.*?href="(.*?)"|'; //parse links preg_match_all($regex,$result,$parts); $links=$parts[1]; foreach($links $link){ echo $link."<br>"; } its output following:
/watch/b4se39an /watch/b4se39an /bscsystem /watch/ifuyzwfw /watch/ifuyzwfw /?sort=v /?sort=c /?sort=l /watch/xk4mvavj /watch/2h7b53vx /watch/d7bt47xb /watch/yh953b17 /watch/tj3z6ki2 /watch/sd4vraxi /watch/f2rnthuh /watch/ey6z8hxa /watch/ybgxgay1 /watch/3iaqyrm1 /help/feedback how can use regular expression extract /watch/..... strings?
modify regex include restriction on /watch/:
$regex = '|<a.*?href="(/watch/.*?)"|'; a simple test script can show it's working:
$tests = array( "/watch/something", "/bscsystem"); $regex = '|<a.*?href="(/watch/.*?)"|'; foreach( $tests $test) { $link = '<a href="' . $test . '"></a>'; if( preg_match( $regex, $link)) echo $test . ' matched.<br />'; } this produce:
/watch/something matched.
Comments
Post a Comment