- How do I install thesoftwarefanatics/php-html-parser?
- Install it with Composer by running composer require thesoftwarefanatics/php-html-parser from your project root. There is no service provider, facade, config file, or publishable asset, so nothing else is registered automatically. You then instantiate the parser or DOM classes directly in your own code or behind a wrapper of your choosing.
- Does this package integrate with Laravel out of the box?
- No. It is a standalone PHP library with no Laravel coupling: no service provider, no facade, no config file, and no publishable assets. Any container binding, configuration, error handling, or encoding normalization is yours to write. In practice it lands as a plain Composer dependency behind a thin wrapper class rather than a first-class framework component.
- How do I find elements with jQuery-style selectors?
- The library provides a CSS-style selector API similar to jQuery for locating tags, attributes, and text within a loaded HTML document. You load the HTML into the parser, then run selectors to extract matching nodes and read their attributes or inner text. This selector convenience is the main reason to choose it over the raw DOM primitives already available through Symfony components.
- Which PHP versions does this package support, including PHP 8.1 and 8.2?
- The 1.8.1 release notes and changelog do not mention the composer.json php constraint, a supported PHP matrix, or PHP 8 compatibility declarations. The CI configuration also appears to still target Travis CI, which suggests the test matrix is stale rather than proven on modern PHP. Check composer.json's platform requirement and run a quick compatibility test on your PHP version before committing to the dependency.
- How do I avoid UTF-8 mojibake or garbled characters when parsing HTML?
- Version 1.8.1 includes a fix for charset meta-tag detection when a semicolon or space follows the charset value, which improves detection but does not guarantee UTF-8 output. You should still normalize input explicitly, for example by converting strings through mb_convert_encoding before handing them to the parser. Without that coercion, non-ASCII text can be mangled in the resulting DOM.
- Is it safe to parse untrusted or user-supplied HTML with this package?
- You need to be careful. Parsing with LIBXML_NOENT enabled can expose you to XXE (XML External Entity) attacks, so avoid that flag or disable external entity loading when handling untrusted markup. Also expect silent truncation on badly malformed markup, so validate or sanitize input and check that parsed output matches expectations before trusting it.
- How much memory does parsing a large HTML document use?
- The library builds a full DOM tree, which typically costs roughly five to ten times the size of the source document in memory. That is fine for a single page but adds up quickly if you scrape or process many documents in a queue worker. Stream or batch your parsing, and raise PHP's memory_limit if you must handle very large pages.
- Should I use this fork or paquettg/php-html-parser v3?
- The 1.8.1 release number matches upstream paquettg/php-html-parser 1.8.1, which suggests the fork is resyncing rather than diverging, meaning the API surface should now align and upstream documentation should be more reliable. If the code has converged, evaluating upstream v3 as a drop-in is a reasonable move before you commit to the fork. Confirm the php constraint in composer.json either way, since neither release clearly documents modern PHP support.
- Is this package actively maintained and safe for production use?
- The maintenance profile is best described as thin rather than abandoned. Version 1.8.1 merged a backlog of older pull requests, including fixes for replaceChild DOM mutation and charset meta-tag parsing, and drew four contributors including a Doctrine core maintainer, which is a positive review signal. However, there is no issue triage, no security advisory coverage, no documented support commitment, and no PHP 8 declaration, so treat it as a dependency you must vet and pin yourself.
- How do I test code that uses this HTML parser in a Laravel test suite?
- Because the library has no framework coupling, you can instantiate it directly in a PHPUnit or Pest test with fixture HTML strings, keeping tests fast and free of container setup. If you wrap it in your own service class, bind a fake or stub of that wrapper in Laravel's container so application tests do not depend on real parsing. Keep fixture files with malformed markup and non-UTF-8 content to cover the truncation and encoding failure modes.