Skip to content

A simple class for manipulating html or include files. Useful for Wordpress child themes.

Notifications You must be signed in to change notification settings

mattbell87/php-mod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

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();

About

A simple class for manipulating html or include files. Useful for Wordpress child themes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages