piradoiv / linklord
A micro library to extract link's information from an HTML string
Requires
- php: >=5.4.0
- phpunit/phpunit: 3.7.*
- squizlabs/php_codesniffer: 1.4.*
- symfony/css-selector: 2.*
- symfony/dom-crawler: 2.*
This package is not auto-updated.
Last update: 2021-07-04 23:00:05 UTC
README
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! :)