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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -