Skip to content

Latest commit

 

History

History
33 lines (26 loc) · 901 Bytes

README.md

File metadata and controls

33 lines (26 loc) · 901 Bytes

php-mod

A simple utility class for manipulating html or include files.

This may be useful for projects such as Wordpress child themes or plugins.

Usage

Create a mod object from a php file:

$mod = new IncludeMod('myfile.php'); 

Say you wanted to insert your own code under a div of class "wrapper":

$insertContent = '<p>Hello World</p>'; //HTML example
$wrapperRegEx = @'/<div[^>]*class="[^"]*wrapper[^"]*"[^>]*>/'; //Regular expression for the open tag
$mod->insertAfter($wrapperRegEx, $insertContent);

Or perhaps you wanted to insert some code before the div?:

$insertContent = '<p>Hello World</p>'; //HTML example
$wrapperRegEx = @'/<div[^>]*class="[^"]*wrapper[^"]*"[^>]*>/'; //Regular expression for the open tag
$mod->insertBefore($wrapperRegEx, $insertContent);

Lastly you'll want to output the modified content:

$mod->output();