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 Link to comment https://forums.phpfreaks.com/topic/220313-removing-spaces-and-lines/ 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; Link to comment https://forums.phpfreaks.com/topic/220313-removing-spaces-and-lines/#findComment-1141652 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? Link to comment https://forums.phpfreaks.com/topic/220313-removing-spaces-and-lines/#findComment-1141712 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); Link to comment https://forums.phpfreaks.com/topic/220313-removing-spaces-and-lines/#findComment-1141718 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 Link to comment https://forums.phpfreaks.com/topic/220313-removing-spaces-and-lines/#findComment-1142139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.