24hoursmedia / php-dom-manipulations
Collections of dom manipulations
v0.1.3
2016-11-21 12:24 UTC
Requires
- php: >=5.6
This package is not auto-updated.
Last update: 2024-12-19 08:41:42 UTC
README
A library to manipulate dom.
Manipulators
GaAddCampaignToLinks
Add google analytics campaign information to all links in a document.
Usage:
$html = '<a href="test.html">a</a><a href="test2.html">a</a><a href="#test">c</a>';
$doc = new \DOMDocument();
$doc->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$m = new \T4\DomManipulations\Manipulator\Ga\GaAddCampaignToLinks();
// source, medium, campaign
$m->modify($doc, 'newsletter-week14', 'email', 'spring');
$newHtml = $doc->saveHTML();
// $newHtml:
// <a href="test.html" utm_source="newsletter-week14" utm_medium="email" utm_campaign="spring">a</a><a href="test2.html" utm_source="newsletter-week14" utm_medium="email" utm_campaign="spring">a</a><a href="#test">c</a>