glicer / link-checker
检查 html 文件、sitemap.xml 和 robots.txt 中的断链
dev-master
2021-01-19 18:14 UTC
Requires
- php: >=5.5
- glicer/simply-html: ^1.0
- guzzlehttp/guzzle: ^6.2
- symfony/console: ^2.3 || ^3.0
- symfony/finder: ^2.3 || ^3.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^4.8 || ^5.7 || ^6.5
- symfony/process: ^2.3 || ^3.0
This package is not auto-updated.
Last update: 2024-09-25 05:46:42 UTC
README
检查 html/json 文件、sitemap.xml、markdown 和 robots.txt 中的断链。
它支持使用
安装
此库可在 Packagist 上找到。
推荐的安装方法是使用 composer。
编辑你的 composer.json
并添加
{ "require": { "glicer/link-checker": "dev-master" } }
安装依赖
php composer.phar install
如何检查 html/json 文件中的链接?
require 'vendor/autoload.php'; use GlLinkChecker\GlLinkChecker; use GlLinkChecker\GlLinkCheckerReport; use Symfony\Component\Finder\Finder; //relative url use host http://lyon.glicer.com to check link $linkChecker = new GlLinkChecker('http://lyon.glicer.com'); //construct list of local html and json files to check $finder = new Finder(); $files = $finder->files()->in('./public')->name("*.html")->name("*.json"); //launch links checking $result = $linkChecker->checkFiles( $files, function ($nbr) { // called at beginning - $nbr urls to check }, function ($url, $files) { // called each $url - $files : list of filename containing $url link }, function () { // called at the end } ); //convert $result array in a temp html file $filereport = GlLinkCheckerReport::toTmpHtml('lyonCheck',$result); //$filereport contain fullpath to html file print_r($filereport);
你可以用浏览器查看 $filereport
如何检查 robots.txt 和 sitemap 文件中的链接?
require 'vendor/autoload.php'; use GlLinkChecker\GlLinkChecker; $linkChecker = new GlLinkChecker('http://lyon.glicer.com'); $result = $linkChecker->checkRobotsSitemap(); print_r($result);
GlLinkChecker::checkRobotsSitemap() 返回一个数组,如下所示
$result = [ 'disallow' => ['error' => ['/img/', '/download/']], 'sitemap' => [ 'ok' => [ '/sitemap.xml' => [ 'ok' => [ '/index.html', '/section/probleme-solution/compresser-css-html-js.html' ] ] ] ] ];
运行测试
从命令行启动
vendor\bin\phpunit
许可证 MIT
联系
作者:Emmanuel ROECKER & Rym BOUCHAGOUR