我是 PHP 新手。我已经尝试了很多次,但无法想出从外部 HTML 中获取所有 mp3 和 mp4 文件名的搜索模式。文件列表的文件扩展名顺序比文件名顺序。如果有任何帮助,我将不胜感激。
$file = 'http://70.123.0.111//lrs/35/';
$searchfor = '<a herf';
echo $searchfor;
// the following line prevents the browser from parsing this as HTML.
header('Content-Type: text/plain');
// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
echo "Found matches:\n";
echo implode("\n", $matches[0]);
}
else{
echo "No matches found";
}
HTML 代码
70.123.0.111 - /lrs/35/
70.123.0.111 - /lrs/35/
[到父目录]
7/17/2008 9:02 PM 178899264 0102.mp3
7/18/2008 12:30 AM 558244970 0102.mp4
7/17/2008 9:38 PM 186016896 0304.mp3
7/18/2008 1 :44 AM 580476123 0304.mp4
7/17/2008 10:13 PM 186478272 0506.mp3
7/18/2008 2:59 AM 581455848 0506.mp4
7/17/2008 10:44 PM 166862592 0708.mp
2008 凌晨 4:02 520139478 0708.mp4
7/17/2008 11:19 PM 188616096 0910.mp3
7/18/2008 5:16 AM 590308801 0910.mp4
12/11/2008 8:15 PM 688347 qfya._m
2008 年 11 月2:08 下午 421978 ym_notes.pdf