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? Quote 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); Quote 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); Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/178645-solved-preg_replace/#findComment-942322 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.