I have string which contain space in its html tags
$mystr = "< h3> hello mom ?< / h3>"
so i wrote regex expression for it to detect the spaces in it
$pattern = '/(?<=<)\s\w+|\s\/\s\w+|\s\/(?=>)/mi';
so next i want to modify the matches by removing space from it and replace it, so any idea how it can be done? so that i can fix my string like
"&lt;h3&gt; hello mom ?&lt;/h3&gt;"
i know there is php function pre_replace but not sure how i can modify the matches
$result = preg_replace( $pattern, $replace , $mystr );
&is not equal to&. Trypreg_replace_callback('/&lt;(?:\s*\/)?\s*\w+\s*&gt;/ui', function($m) { return preg_replace('/\s+/u', '', $m[0]); }, $mystr).preg_replace('/&lt;\s+/ui','&lt;',$mystr)would do the job'/&lt;(?:\s*\/)?\s*\w+\s*&gt;/ui', only deals with tags that have no attributes, like the example in the question.