PHPackages                             ressio/pharse - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. ressio/pharse

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

ressio/pharse
=============

Fastest PHP HTML Parser

0.2.0(11y ago)8478.4k—1.9%15[7 issues](https://github.com/ressio/pharse/issues)GPLPHPPHP &gt;=5.0.0

Since Mar 24Pushed 8y ago8 watchersCompare

[ Source](https://github.com/ressio/pharse)[ Packagist](https://packagist.org/packages/ressio/pharse)[ Docs](https://github.com/ressio/pharse)[ RSS](/packages/ressio-pharse/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

Pharse
======

[](#pharse)

Fastest PHP HTML Parser

---

The Pharse is fork of [Ganon](http://code.google.com/p/ganon) library and gives access to HTML/XML documents in a very simple object oriented way. It eases modifying the DOM and makes finding elements easy with CSS3-like queries.

Pharse is:

- A universal tokenizer
- A HTML/XML/RSS DOM Parser
    - Ability to manipulate elements and their attributes
    - Supports HTML5
    - Supports invalid HTML
    - Supports UTF8
    - Can perform advanced CSS3-like queries on elements (like jQuery -- namespaces supported)
- A HTML beautifier (like HTML Tidy)
    - Minify CSS and Javascript
    - Sort attributes, change character case, correct indentation, etc.
- Extensible
    - Parsing documents using callbacks based on current character/token
    - Operations separated in smaller functions for easy overriding
- Fast
- Easy

Quick start
-----------

[](#quick-start)

```
include('path/pharse.php');

// Parse the google code website into a DOM
$html = Pharse::file_get_dom('http://code.google.com/');
```

After including Pharse and loading the DOM, it is time to get started.

### Access

[](#access)

Accessing elements is made easy through the CSS3-like selectors and the object model.

```
// Find all the paragraph tags with a class attribute and print the
// value of the class attribute
foreach($html('p[class]') as $element) {
  echo $element->class, "\n";
}

// Find the first div with ID "gc-header" and print the plain text of
// the parent element (plain text means no HTML tags, just the text)
echo $html('div#gc-header', 0)->parent->getPlainText();

// Find out how many tags there are which are "ns:tag" or "div", but not
// "a" and do not have a class attribute
echo count($html('(ns|tag, div + !a)[!class]');
```

### Modification

[](#modification)

Elements can be easily modified after you've found them.

```
// Find all paragraph tags which are nested inside a div tag, change
// their ID attribute and print the new HTML code
foreach($html('div p') as $index => $element) {
  $element->id = "id$index";
}
echo $html;

// Center all the links inside a document which start with "http://"
// and print out the new HTML
foreach($html('a[href ^= "http://"]') as $element) {
  $element->wrap('center');
}
echo $html;

// Find all odd indexed "td" elements and change the HTML to make them links
foreach($html('table td:odd') as $element) {
  $element->setInnerText(''.$element->getPlainText().'');
}
echo $html;
```

### Beautify

[](#beautify)

Pharse can also help you beautify your code and format it properly.

```
// Beautify the old HTML code and print out the new, formatted code
Pharse::dom_format($html, array('attributes_case' => CASE_LOWER));
echo $html;
```

License
-------

[](#license)

Pharse is licensed under the [Artistic License/GPL](http://dev.perl.org/licenses/)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

4073d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a946f696d8246c2429158278cb7bb77f2965ce9b2ebf7d5dd0c4a133d1305f0?d=identicon)[dryabov](/maintainers/dryabov)

---

Top Contributors

[![dryabov](https://avatars.githubusercontent.com/u/378044?v=4)](https://github.com/dryabov "dryabov (53 commits)")[![ressio](https://avatars.githubusercontent.com/u/6097122?v=4)](https://github.com/ressio "ressio (1 commits)")

---

Tags

phpparserhtmlHTML5dom

### Embed Badge

![Health badge](/badges/ressio-pharse/health.svg)

```
[![Health](https://phpackages.com/badges/ressio-pharse/health.svg)](https://phpackages.com/packages/ressio-pharse)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sunra/php-simple-html-dom-parser

Composer adaptation of: A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way! Require PHP 5+. Supports invalid HTML. Find tags on an HTML page with selectors just like jQuery. Extract contents from HTML in a single line.

1.3k9.4M61](/packages/sunra-php-simple-html-dom-parser)[simplehtmldom/simplehtmldom

A fast, simple and reliable HTML document parser for PHP.

1921.3M14](/packages/simplehtmldom-simplehtmldom)[oscarotero/html-parser

Parse html strings to DOMDocument

165.0M1](/packages/oscarotero-html-parser)[hexydec/htmldoc

A token based HTML document parser and minifier. Minify HTML documents including inline CSS, Javascript, and SVG's on the fly. Extract document text, attributes, and fragments. Full test suite.

2610.3k3](/packages/hexydec-htmldoc)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
