2017 © Pedro Peláez
 

library munchitos

Objectify HTML like a boss.

image

piradoiv/munchitos

Objectify HTML like a boss.

  • Monday, March 31, 2014
  • by piradoiv
  • Repository
  • 1 Watchers
  • 1 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 17 % Grown

The README.md

Munchitos

Build Status, (*1)

This library aims to make developer's life easier while trying to parse the HTML contents., (*2)

Features

At the moment, Munchitos currently have these features:, (*3)

  • Returns the title of the page.
  • Extract Links and Images from the contents.
  • Detects meta description.
  • Gives the canonical URL, if present.
  • List every linked stylesheet.
  • Detects the charset encoding.

In the future, Munchitos aims to support:, (*4)

  • Semantic microformat.

How to install

Composer is the easier way, just add the library to the dependancies:, (*5)

{
  "require": {
    "piradoiv/munchitos": "dev-master"
  }
}

Remember to call composer install or composer update after adding composer.json file. There are loads of information about setting up Composer on your project., (*6)

Munchitos goal isn't to download the HTML itself, so I recommend to also install a cURL wrapper, like shuber/curl., (*7)

How to use

<?php
// First you'll have to load composer and create
// a Munchitos instance.
require 'vendor/autoload.php';
$munchitos = new PiradoIV\Munchitos\Munchitos;

// Optionally but definitely you want to do it,
// set the source URL from where you downloaded
// the HTML contents.
$munchitos->url("http://www.example.com/foo/bar.html");

// Fill it with the HTML
$html = '<html><body>

Hello World!, (*8)

</body></html>'; $munchitos->html($html); // And start calling any information you need. echo $munchitos->title();

$munchitos->title()

Returns the title of the page, trimming the spaces., (*9)

$munchitos->description()

If there is any meta description tag, it returns its contents., (*10)

$munchitos->canonical()

Some websites specifies a canonical URL, there you go., (*11)

$munchitos->stylesheets()

Returns a list (if any) of stylesheets urls used on current HTML., (*12)

$munchitos->charset()

Searchs for the charset tag and returns it content., (*13)

Returns an array of Link instances. Link class contains these helpful methods:, (*14)

  • href()
  • title()
  • target()
  • isNoFollow() / isFollow()

$munchitos->images()

Returns an array of Image instances. Like with Link class, it includes some methods:, (*15)

  • altText() or alt()
  • src()
  • isLinked()

Acknowledges

I want to thank the Open Source community, specially Composer guys, Symfony libraries and the PHP League for their project template., (*16)

Contribute

Simply send a pull request, but please ensure your code doesn't breaks the tests and it's written with the PSR-2 coding style., (*17)

Contact

I'm @PiradoIV on Twitter, give me a shout if you need a hand with this library., (*18)

The Versions