I have a string assigned to the variable $ output. I want to use QueryPath to iterate over a string and add a class to each matched element.
I currently have:
$output = qp($output)->find('table')->addclass('table')->html();
The only problem with this is deleting the contents of $ output before the first match. Is there a way to use QueryPath to find a match and then add a class while keeping the contents of $ output intact?
EDIT:
Pseudo code:
$output = '<table class="temp"><blah></blah></table>';
Magic QueryPath
$output = '<table class="temp blah"><blah></blah></table>';
source
share