PHP Parser 1.20

While devel­op­ing of our upcom­ing PHP Typog­ra­phy project, it became clear we needed a PHP based solu­tion to parse and reassem­ble HTML and its con­tained text. We were unable to find any­thing that suited our needs, so we built one. When done, we real­ized that what we had built was pow­er­ful, flex­i­ble, effi­cient, and valu­able… even out­side the ini­tial PHP Typog­ra­phy project. So, we are releas­ing PHP Parser as a stand-​​alone project for your use. We hope you find it as help­ful as we have.

PHP Parser con­sists of two classes: parseHTML and parsedText. As you may have guessed, parseHTML parses HTML and parseText parses text. Using PHP Parser is as easy as this:

$html = "raw html..."

include( 'path/to/php-parser.php' );
$parsedHTML = new parseHTML( );
$parsedHTML->load( $html );
$parsedHTML->unlock_text( );
$tagsToIgnore = $parsedHTML->get_tags_by_name(
	array( "code", "pre", ... )
$parsedHTML->lock_children( $tagsToIgnore );
$unlockedTexts = $parsedHTML->get_unlocked_text( );

foreach( $unlockedTexts as &$unlockedText ) {
	$parsedText = new parseText( );
	$parsedText->load( $unlockedText );
	$words = $parsedText->get_words( );
	foreach ( $words as &$word ) {
		// do stuff to $word["value"]
	$parsedText->update( $words );
	$unlockedText[ "value" ] = $parsedText->unload( );

$parsedHTML->update( $unlockedTexts );
$html = $parsedHTML->unload( );

If you use PHP Parser in a project, please let us know. We’d love to link to it.

Your feed­back is much appre­ci­ated. How can we make this plu­gin bet­ter? Email us at info@​kingdesk.​com

Leave a Comment

Please note our comment and privacy policies.