在文本上找到带正则表达式的网址(find url with regex on text)
有很多像这样的主题,但我不知道我尝试了多少错误,所以这是原始文本
onclick="NewWindow('http://google.com','name','800','600','yes');return false">这是我的代码
$re1='(onclick)'; $re2='(=)'; $re3='(.)'; $re4='(NewWindow)'; $re5='(\\()'; $re6='(.)'; $re7='((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))'; $c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6.$re7."/is", $txt, $matches); print_r($matches);任何人都可以帮助我使用正则表达式和PHP获取网址?
这段代码有什么问题?
问候
there are a lot of topics like this one but i don't know what the error i tried a lot so this is the original text
onclick="NewWindow('http://google.com','name','800','600','yes');return false">this is my code
$re1='(onclick)'; $re2='(=)'; $re3='(.)'; $re4='(NewWindow)'; $re5='(\\()'; $re6='(.)'; $re7='((?:http|https)(?::\\/{2}[\\w]+)(?:[\\/|\\.]?)(?:[^\\s"]*))'; $c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6.$re7."/is", $txt, $matches); print_r($matches);any one can help me to get the url using regular expression and php??
what is the wrong with this code?
Regards
最满意答案
preg_match("/NewWindow\('([^']*)'/",$txt, $matches);matches [1]包含url
这是你需要的吗?
(编辑:放入代码块,因为括号没有转义为correclty
preg_match("/NewWindow\('([^']*)'/",$txt, $matches);matches[1] contains the url
is it what you need ?
(edit: put in code block because a parenthesis was not escaped correclty
更多推荐
发布评论