2017 © Pedro Peláez
 

library link-checker

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

image

glicer/link-checker

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

  • Saturday, August 27, 2016
  • by emmanuelroecker
  • Repository
  • 1 Watchers
  • 18 Stars
  • 311 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 1 Versions
  • 3 % Grown

The README.md

php-linkchecker

Scrutinizer Code Quality Build Status Coverage Status SensioLabsInsight, (*1)

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

It's working with :, (*3)

Installation

This library can be found on Packagist., (*4)

The recommended way to install is through composer., (*5)

Edit your composer.json and add :, (*6)

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

Install dependencies :, (*7)

php composer.phar install
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, (*8)

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 :, (*9)

$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 :, (*10)

vendor\bin\phpunit

License MIT

Contact

Authors : Emmanuel ROECKER & Rym BOUCHAGOUR, (*11)

Web Development Blog - http://dev.glicer.com, (*12)

The Versions