jaxdevil Posted May 7, 2008 Share Posted May 7, 2008 I am getting back the results from a variable as $100.00 for example, I would like to make that result be just 100, no $ at the beginning and no .00 at the end. How do you do this? Thanks, SK Quote Link to comment https://forums.phpfreaks.com/topic/104583-solved-dropping-first-symbol-or-character-from-a-variable-return/ Share on other sites More sharing options...
kenrbnsn Posted May 7, 2008 Share Posted May 7, 2008 You can use ltrim and explode: <?php $str = '$100.00'; list ($str) = explode('.',ltrim($str,'$')); echo $str; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/104583-solved-dropping-first-symbol-or-character-from-a-variable-return/#findComment-535330 Share on other sites More sharing options...
jaxdevil Posted May 7, 2008 Author Share Posted May 7, 2008 Thanks. That is definitely more elegant than what I came up with in the interim... <?php $string = $rate; $new_string = preg_replace("/[^a-zA-Z0-9s]/", "", $string); $newstring = substr($new_string, 0, -2); echo $newstring ?> Quote Link to comment https://forums.phpfreaks.com/topic/104583-solved-dropping-first-symbol-or-character-from-a-variable-return/#findComment-535333 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.