Forum Moderators: coopster
$str = '<html>
--<head>
----<title>This is it</title>
--</head>
--<body>
----<p>Content goes here</p>--<img src="somepix.jpg" alt="somepix">
--</body
</html>
';
How can I use the preg_replace to replace all white space between tag, at the beginning of the line, and at end of line without affecting content between tag to have a result like this:
<html><head><title>This is it</title></head><body><p>Content goes here</p><img src="somepix.jpg" alt="somepix"></body</html>
Can preg_replace do it in one pass? Currently, my code need two passes to achive this:
$str = preg_replace("/>\s+</","><",$str); //remove between tag
$str = preg_replace("/^\s+([\S\s]+)\s+$/","$1",$str); //remove at the begining and ending of line
Or there is just another method to achive this, your advice is appreciated, thank you.
I would just trim it.
$str = trim [php.net](preg_replace('/>\s+</','><',$str));