piradoiv/linklord

This package is abandoned and no longer maintained. No replacement package was suggested.

A micro library to extract link's information from an HTML string

1.0.0 2013-06-25 13:45 UTC

This package is not auto-updated.

Last update: 2021-07-04 23:00:05 UTC


README

Build Status

PHP Micro library to extract links from an HTML string.

How to install

The easiest way to install the library is using Composer.

{
  "require": {
    "piradoiv/linklord": "1.*"
  }
}

Please notice the library requires at least PHP 5.3 in order to work (tested on 5.3.26 and 5.4.16)

How to use it

# Require Composer autoloader
require 'vendor/autoload.php';

$html = '<html><body><a href="http://www.example.com/">Example</a></body></html>';
$parser = new \PiradoIV\Html\LinkLord\Parser($html);
$links = $parser->getLinks();

foreach ($links as $node) {
  echo "{$node->anchorText}\n";
}

Other features

Follow/Nofollow

LinkLord is able to know whether the links are followed or not.

$node->isNoFollow;

What about images?

If the link has an image child, it will be detected.

$node->isImage;

Mentions

Looking for mentions on the code?, LinkLord is able to recognise mentions on the text, this means if there is a 'www.example.com' on the text and is not linked, this will count as a mention.

$possibleMentions = array('www.example.com', 'www.anotherdomain.com');
$mentions = $parser->getMentions($possibleMentions);

Contact me

If you need more examples or help, please contact me on Twitter, @PiradoIV :)

Enjoy! :)