Find and Replace with QueryPath

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>';
+3
source share
1 answer

try removing html ()

$output = qp($output)->find('table')->addclass('table');

To display:

$output->writeHTML();

html () :: Replaces the child content of the current element or elements in an HTML document

0
source

All Articles