由于我找不到问题的确切答案,我决定寻求帮助,在这里发布我的问题。因此,我有一个通过 file_get_contents
获取的页面内容,并希望 preg_match
此网址:
http://sample.com/Last/LastSearch.ashx?q=cnt=1&day=5&keyword=sample&location=15&view=v
来自
<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>
请帮助我。
最佳答案
为什么不使用 DOM?这就是它的用途...
如果您坚持使用正则表达式,请尝试(在 PHP 中)
if (preg_match('/<a href="javascript:LastURL\(\'([^\'])*\'/', $subject, $regs)) {
$result = $regs[1];
} else {
$result = "";
}
或(在 JavaScript 中)
var myregexp = /<a href="javascript:LastURL\('([^'])*'/;
var match = myregexp.exec(subject);
if (match != null) {
result = match[1];
} else {
result = "";
}
关于php - preg_match url 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6109557/