PHP code example of kuria / simple-html-parser

1. Go to this page and download the library: Download kuria/simple-html-parser 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/ */

    

kuria / simple-html-parser example snippets



   

   use Kuria\SimpleHtmlParser\SimpleHtmlParser


   

   foreach ($parser as $element) {
       print_r($element);
   }

.. code:: php

   

   $parser->rewind()


   

   $parser->getHtml(); // get entire document
   $parser->getHtml($element); // get single element


``getSlice()`` - get part of the HTML
=====================================

The ``getSlice()`` method returns a part of the HTML content.

Returns an empty string for negative or out-of-bounds ranges.

.. code:: php

   

   $slice = $parser->getSlice(100, 200)


   

   $slice = $parser->getSliceBetween($openingTag, $closingTag)


   

   $element = $parser->find(SimpleHtmlParser::OPENING_TAG, 'title')


   

   $html = <<<HTML
   <!doctype html>
   <meta charset="utf-8">
   <title>Foo bar</title>
   <h1>Baz qux</h1>
   HTML