Hello,
I have the following string:
$string=" <tag> <hello> <bye> <dog>
<cat>
<pig> ";
I need to replace all the white characters outside of the < and > so that it ends up like this:
$string="<tag><hello><bye><dog><cat><pig>";
Any help?
Thanks,
-dr
Perhaps something along these lines?
$string=" <tag> <hello> <bye> <dog> <cat> <pig> "; function stripSpaces($a){ return preg_replace('#\s+#', '', $a[0]); } $string = preg_replace_callback('#(^|>)[^<]+<#', 'stripSpaces', $string); echo $string;
Thanks! Works like a charm!