Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

newcomer's avatar

Any laravel packages for collecting html tags from html page

I want to collect all h1 and P tags in html page. Is there any php script or laravel packages available I need to know. Please tell any one

Thanks...

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

Yes, there are Laravel packages available that can help you collect HTML tags from an HTML page. One such package is called "PHP Simple HTML DOM Parser." This package allows you to easily parse HTML and extract specific tags and their contents.

To use this package, you can install it via Composer by running the following command in your terminal:

composer require sunra/php-simple-html-dom-parser

Once installed, you can use the following code to extract all h1 and p tags from an HTML page:

use Sunra\PhpSimple\HtmlDomParser;

// Load the HTML from a file or URL
$html = HtmlDomParser::file_get_html('http://www.example.com/');

// Find all h1 tags and print their contents
foreach($html->find('h1') as $h1) {
    echo $h1->innertext . '<br>';
}

// Find all p tags and print their contents
foreach($html->find('p') as $p) {
    echo $p->innertext . '<br>';
}

This code will load the HTML from a file or URL, find all h1 and p tags, and print their contents. You can modify this code to suit your specific needs.

Please or to participate in this conversation.