[b]code1[/b]
function space($str) {
$strOut = '';
for ($i = 0; $i < strlen($str); $i++) {
$strOut .= ( substr($str, $i, 1) == ' ') ? ' ' : substr($str, $i, 1);
}
return $strOut;
}
$function_space=0;
$myVar='1 2 3';
echo space($myVar);
[b]result1[/b]
1 2 3
The code1 above produces the result1 above(Please notice there are 2 spaces between 2 and 3).
if the value of $myVar is like the below
<div style="color:red">1 2 3</div>
The result of it will be '<div style=“color:red”>1 2 3</div>.
I like to remove which is between open tag(<) and close tag(>).
I can remove with the code “str_replace(‘div ’,'div ',$myVar);” in the case of the above, but there are variety of selectors and properties inside tags.
How can I remove all spaces which is between open tag(<) and close tag(>) ?
I like to put into contents (
1 2 3
) only which is outside tags instead of inside tags.