0

我需要帮助来执行此操作。我有一个这样的字符串:

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Formatting the report</title><meta http-equiv="refresh" content="5;url=/file/xslt/download/?fileName=somename.pdf"> </head>

我需要提取 fileName 参数。这该怎么做?

我用正则表达式可以做到这一点,但我不太清楚这一点。

谢谢!

4

3 回答 3

1

试试这个..

这将捕获文件名

模式如下

/fileName=(.+?)\"/

<?php
$subject = "<!doctype html> <html> <head> <meta charset="utf-8"> <title>Formatting the report</title><meta http-equiv="refresh" content="5;url=/file/xslt/download/?fileName=somename.pdf"> </head>";
$pattern = '/fileName=(.+)"/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 2);
print_r($matches);
?>

$1->包含文件名

演示

于 2014-02-13T10:29:13.907 回答
0

尝试以下方式:

$str = '<!doctype html> <html> <head> <meta charset="utf-8"> <title>Formatting the report</title><meta http-equiv="refresh" content="5;url=/file/xslt/download/?fileName=somename.pdf"> </head>';

preg_match('@fileName=(.*)"@', $str, $matches);

print_r($matches);
于 2014-02-13T10:22:34.157 回答
0

php simple html dom是跟踪 html 并通过选择器(如 Jquery 选择器)查找 html 元素的干净和好方法。

于 2014-02-13T10:25:16.097 回答