php - I want to remove spaces between tags in HTML -
$html
contains html code. in case has spaces between > <
divisions , between >
or <
, inner text, need remove them.
this code:
$html = '<div> </div> <div> here</div>'; $html = preg_replace('/>\s+</', "><", $html);
but it’s not removing spaces between > <
or > here
.
<div></div><div>here</div>
any suggestion?
for spaces, use str_replace:
$html = '<div> </div> <div> here</div>'; $string = str_replace(' ', '', $html);
for whitespace, use preg_replace:
$string = preg_replace('/\s+/', '', $html);
for after div space remove only, user
$html = '<div calss="something"> </div> <div> here</div>'; $string = str_replace('> ', '>', $html);
Comments
Post a Comment