1. Go to this page and download the library: Download osmuhin/html-meta library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
osmuhin / html-meta example snippets
use Osmuhin\HtmlMeta\Crawler;
$meta = Crawler::init(url: 'https://google.com')->run();
echo $meta->title; // Google
public function canHandle(): bool
{
}
public function handle(): void
{
}
class TitleDistributor extends \Osmuhin\HtmlMeta\Distributors\AbstractDistributor
{
public function canHandle(): bool
{
return $this->el->name === 'title';
}
public function handle(): void
{
$this->meta->title = $this->el->innerText;
}
}
use Osmuhin\HtmlMeta\Distributors\TitleDistributor;
class MyCustomTitleDistributor extends TitleDistributor
{
public function handle(): void
{
$this->meta->title = 'Prefix for title ' . $this->el->innerText;
}
}
$crawler = Crawler::init(url: 'https://google.com');
$crawler->distributor->setSubDistributor(
MyCustomTitleDistributor::class,
TitleDistributor::class
);
$meta = $crawler->run();
$meta->title === 'Prefix for title Google';