php - preg_match url 模式

标签 php javascript preg-match file-get-contents

由于我找不到问题的确切答案,我决定寻求帮助,在这里发布我的问题。因此,我有一个通过 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/

相关文章:

javascript - 不变违规 : Text strings must be rendered within a component

PHP:字符串到正则表达式

PHP难的preg_match

php - 同时在服务器和用户上下载

javascript - 使用 npm smarttap-react 时出现 ReferenceError : window is not defined in Next. js

php - 如何获取有关已发送 PHP curl 请求的信息

javascript - 由于浏览器警告,从下拉列表中选择不会填充第二个相关下拉列表

php - 使用 preg_match 检查文本格式

php - 在表超链接中创建回显结果后

php - 仅声明一次 Use "Namespace"初始化并且所有文件都为对象获得相同的命名空间