Created
October 17, 2014 09:38
-
-
Save HikoQiu/b8de0a7b4b03a90dff77 to your computer and use it in GitHub Desktop.
正则匹配网页链接
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$rawTitle = '<meta name="description" content="hello world">'; | |
$res = preg_match("/<meta name=\"(\w+)\" content=\"(.*?)\">/is",$rawTitle,$booktitle); | |
var_dump($booktitle, $res); | |
$str = 'foobar: 2008'; | |
preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches); | |
var_dump($matches); | |
function get_all_url($code){ | |
preg_match_all('/<a\shref=[\"|\'](.*?)[\"|\'].*?>(.*?)<\/a>/i', $code, $arr); // *? 表示lazy模式(勉强模式)匹配* | |
return $arr; | |
} | |
$linkStr = '<a href="aa.com">hello</a><a href="bbb.com">bbb</a>'; | |
$linkStr = file_get_contents('http://huxiu.com'); | |
var_dump(get_all_url($linkStr)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment