Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.
/ html-linklord Public archive

Micro library to extract links from an HTML string

Notifications You must be signed in to change notification settings

piradoiv/html-linklord

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LinkLord

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! :)

About

Micro library to extract links from an HTML string

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages