king.oslo Posted June 6, 2009 Share Posted June 6, 2009 Hey everyone, I am looking to use preg_replace() twice. Can you please tell me how to: - replace all characters in a $sting that are not numbers ',' and '.' with ''. - replace all ',' in $string with '.' Thanks! Marius Link to comment https://forums.phpfreaks.com/topic/161143-solved-preg_replace-replace-all-letters-apart-from-numbers-and/ Share on other sites More sharing options...
.josh Posted June 6, 2009 Share Posted June 6, 2009 $string = preg_replace('~[^0-9,.]~','',$string); $string = str_replace(',','.',$string); Link to comment https://forums.phpfreaks.com/topic/161143-solved-preg_replace-replace-all-letters-apart-from-numbers-and/#findComment-850387 Share on other sites More sharing options...
Ken2k7 Posted June 6, 2009 Share Posted June 6, 2009 What good will the second one do? Link to comment https://forums.phpfreaks.com/topic/161143-solved-preg_replace-replace-all-letters-apart-from-numbers-and/#findComment-850389 Share on other sites More sharing options...
.josh Posted June 6, 2009 Share Posted June 6, 2009 $string = "abc123,456.78"; $string = preg_replace('~[^0-9,.]~','',$string); // new value: 123,456.78 $string = str_replace(',','.',$string); // new value: 123.456.78 Link to comment https://forums.phpfreaks.com/topic/161143-solved-preg_replace-replace-all-letters-apart-from-numbers-and/#findComment-850392 Share on other sites More sharing options...
Ken2k7 Posted June 6, 2009 Share Posted June 6, 2009 Oh I overlooked it. Sorry about that Crayon Violet. Link to comment https://forums.phpfreaks.com/topic/161143-solved-preg_replace-replace-all-letters-apart-from-numbers-and/#findComment-850395 Share on other sites More sharing options...
king.oslo Posted June 6, 2009 Author Share Posted June 6, 2009 Crayon Violent: Thank you!oz Link to comment https://forums.phpfreaks.com/topic/161143-solved-preg_replace-replace-all-letters-apart-from-numbers-and/#findComment-850398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.