[PHP] Replace multiple spaces by one (by RegExp)

in php •  7 years ago 

Hello my friends!

Today, during parsing websites, I faced with such price string:

"                                  20,00             
                           €           
                                *          "

Parsing such prices is not very comfortable...

But, I found very useful way to solve it:

$string = preg_replace('!\s+!', ' ', $string);

Previous string become:

" 20,00 € * "

And this is good string for parsing.

I hope that it will help somebody. Have a nice day :-)


P.S. Many thanks for guys here:
https://stackoverflow.com/questions/2368539/php-replacing-multiple-spaces-with-a-single-space

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!