for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Flynt\Utils;
use DOMDocument;
class DomNode
{
public static function setSrcDataAttribute($nodeHtml, $elementTagName, $attributeName, $toAddGetParams)
$output = '';
$DOM = new DOMDocument();
$DOM->loadHTML($nodeHtml);
$domNodes = $DOM->getElementsByTagName($elementTagName);
foreach ($domNodes as $node) {
$attribute = $node->getAttribute($attributeName);
$attribute = add_query_arg($toAddGetParams, $attribute);
$node->removeAttribute($attributeName);
$node->setAttribute("data-{$attributeName}", $attribute);
$output .= $DOM->saveHTML($node);
}
return $output;