I need help to do this operation. I Have a string like this:

<!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>

I need to extract the fileName parameter. How to do this?

I thing that is possible with regex, but I do not know well this.

Thanks!

有帮助吗?

解决方案

Try this..

This will capture the filename

The Pattern is given below

/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->Contains the file name

demo

其他提示

Try something along the lines of:

$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);

php simple html dom is clean and good way for trace html and find html elements by selector's like Jquery selectors.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top