Could be made better? str_replace and preg_replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
LuaMadman
Forum Commoner
Posts: 35
Joined: Tue Jul 20, 2010 6:58 am

Could be made better? str_replace and preg_replace

Post by LuaMadman »

I use the following code to remove letters and space and replace comma with a dot

Code: Select all

str_replace(',','.',preg_replace("/[^0-9,]/",'',$array[42]))
Can it done with only preg_replace? or some other call?
I do it on array 8,42 and 43
they can have the following strings:
2Â 840kr
68kr
1Â 134,00 kr
860,00 kr
Post Reply