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

in #php7 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

Coin Marketplace

STEEM 0.15
TRX 0.23
JST 0.032
BTC 84828.10
ETH 2183.93
USDT 1.00
SBD 0.67