tqla Posted October 22, 2009 Share Posted October 22, 2009 Hello. My $beforediscountedPrice variable value is $75 and I need to use the value 75 without the dollar sign. How can I remove it? I have tried: $beforediscountedPrice = preg_replace('$','',$beforediscountedPrice); But it does not work, How can I do this correctly? Or, is there a way to convert monetary values that have a dollar sign to regular numbers? Link to comment https://forums.phpfreaks.com/topic/178645-solved-preg_replace/ Share on other sites More sharing options...
Mchl Posted October 22, 2009 Share Posted October 22, 2009 $beforediscountedPrice = substr($beforediscountedPrice,1); Link to comment https://forums.phpfreaks.com/topic/178645-solved-preg_replace/#findComment-942291 Share on other sites More sharing options...
Psycho Posted October 22, 2009 Share Posted October 22, 2009 Although, if there is the possibility that it may not always be the first character that you need to get rid of, you can remove all characters that are not 0-9 or a decimal using the following: $beforediscountedPrice = preg_replace('/[^\d.]/','',$beforediscountedPrice); Link to comment https://forums.phpfreaks.com/topic/178645-solved-preg_replace/#findComment-942321 Share on other sites More sharing options...
tqla Posted October 22, 2009 Author Share Posted October 22, 2009 Thank you Mchl. Works well. I am reading up on substr() now. Thank you too mjdamato. Link to comment https://forums.phpfreaks.com/topic/178645-solved-preg_replace/#findComment-942322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.