Skip to content

Check broken links in html / json files, sitemap.xml, markdown and robots.txt

License

Notifications You must be signed in to change notification settings

emmanuelroecker/php-linkchecker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-linkchecker

Scrutinizer Code Quality Build Status Coverage Status SensioLabsInsight

Check broken links in html / json files, sitemap.xml, markdown and robots.txt.

It's working with :

Installation

This library can be found on Packagist.

The recommended way to install is through composer.

Edit your composer.json and add :

{
    "require": {
       "glicer/link-checker": "dev-master"
    }
}

Install dependencies :

php composer.phar install

How to check links in html / json files ?

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

you can view $filereport with your browser

How to check links in robots.txt and sitemap files ?

require 'vendor/autoload.php';

use GlLinkChecker\GlLinkChecker;

$linkChecker = new GlLinkChecker('http://lyon.glicer.com');
$result      = $linkChecker->checkRobotsSitemap();

print_r($result);

GlLinkChecker::checkRobotsSitemap() return an array like :

$result = [
    'disallow' =>
        ['error' => ['/img/', '/download/']],
    'sitemap'  =>
        [
            'ok' => [
                '/sitemap.xml' =>
                    [
                        'ok' =>
                            [
                                '/index.html',
                                '/section/probleme-solution/compresser-css-html-js.html'
                            ]
                    ]
            ]
        ]
];

Running Tests

Launch from command line :

vendor\bin\phpunit

License MIT

Contact

Authors : Emmanuel ROECKER & Rym BOUCHAGOUR

Web Development Blog - http://dev.glicer.com

About

Check broken links in html / json files, sitemap.xml, markdown and robots.txt

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •