I am looking into a way to clean a generated class attribute using regular expressions.
Having this html
<div class=" class1 class2 ">
and using this preg
$string = preg_replace('/class=["\'](?P<class>[^"\'<>]+)["\']/i', 'class="$1"', $string);
How do I tell php to trim the trailing spaces around $1? ($1 is basically whats inside class)
Are there other ways to detect and replace end spaces?
Thank you
Edited: basically I am tring to do this
'class="'.trim($1).'"'
but $1 is not available as variable. I already tried $$1 and ${$1}. Maybe there is some other syntax to do this.