mraza Posted December 1, 2010 Share Posted December 1, 2010 Hi, I am trying to parse a html page, but i get a lot of empty spaces, please any idea how can i remove spaces, here is my text: this goes here one line here some other line here see there is a lot of space between text, thanks for any help Quote Link to comment Share on other sites More sharing options...
dawsba Posted December 1, 2010 Share Posted December 1, 2010 function replace_multiple_spaces($string) { // tabs, new lines and carriages are also replaced $string = ereg_replace("[ \t\n\r]+", " ", $string); return $string; } $string = "This is a dummy text. "; $new_string = replace_multiple_spaces($string); // Outputs: This is a dummy text echo $new_string; Quote Link to comment Share on other sites More sharing options...
OldWest Posted December 1, 2010 Share Posted December 1, 2010 What php function are you using to parse the page? Quote Link to comment Share on other sites More sharing options...
dreamwest Posted December 1, 2010 Share Posted December 1, 2010 This will strip all whitespace and normalizes your string $text = "This is a dummy text. "; echo preg_replace('!\s+!', ' ', $text); Quote Link to comment Share on other sites More sharing options...
mraza Posted December 2, 2010 Author Share Posted December 2, 2010 Thanks guys, it worked well with preg_replace function What php function are you using to parse the page? using php-curl functions Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.