php收罗CSS文件名

许多时候要收罗网站数据,假如你想要采到一些与样式有关的对象也可以收罗一些文件如CSS 文件这样的东东。

以下只是简朴地写出如何收罗一个页面下的CSS文件名,记着只是CSS文件名。想要更深入收罗,好比收罗CSS文件内容,尚有图片,那就等今后再阐明,不多说上简朴代码:

form.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <form method="get" action="post.php"> <input type="text"> <input type="submit" value="提交"> </form>

post.php 

<?php if($_GET) { $url= $_GET['q']; $data = file_get_contents($url); //http://www.qq.com $preg = '/<link (.*?)href="(.*?\.css)"(.*?)\/>/i'; preg_match_all($preg,$data,$css_data,PREG_SET_ORDER); echo '<ol>'; foreach ( $css_data as $v){ echo '<li>'; echo $v[2].'<br>'; echo '</li>'; } echo '</ol>'; } ?>


附件下载/演示源码:
【 getcss.rar 】 655字节

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/7989.html