[英]preg_match url pattern
as I cant find exact answer to my question I decided to ask for help posting my question here.因为我找不到我的问题的确切答案,所以我决定寻求帮助,在这里发布我的问题。 So, I have a page content which I get with file_get_contents
and want to preg_match
this url:所以,我有一个页面内容,我通过file_get_contents
获得并希望preg_match
这个 url:
http://sample.com/Last/LastSearch.ashx?q=cnt=1&day=5&keyword=sample&location=15&view=v
from从
<a href="javascript:LastURL('http://sample.com/Last/LastSearch.ashx?q=cnt=1&day=5&keyword=sample&location=15&view=v');" id="Last" rel="nofollow" class="Last" onclick="javascript:hideCss('LastCSS');hideCss('FirstRCSS');">Last</a>
Please help me.请帮我。
Why not use the DOM?为什么不使用 DOM? That's what it's for...这就是它的用途...
If you insist on a regex, try (in PHP)如果您坚持使用正则表达式,请尝试(在 PHP 中)
if (preg_match('/<a href="javascript:LastURL\(\'([^\'])*\'/', $subject, $regs)) {
$result = $regs[1];
} else {
$result = "";
}
or (in JavaScript)或(在 JavaScript 中)
var myregexp = /<a href="javascript:LastURL\('([^'])*'/;
var match = myregexp.exec(subject);
if (match != null) {
result = match[1];
} else {
result = "";
}
As long as the url is always going to start with http:// then you could use the following expression within your preg_match:只要 url 总是以 http:// 开头,那么您可以在 preg_match 中使用以下表达式:
(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.