Jump to content

Recommended Posts

str_replace(mixed $search  , mixed $replace  , mixed $subject);

 

??

 

<?php
$dollar = "$2,343.23";
$dollar = str_replace("$","",$dollar);
$dollar = str_replace(",","",$dollar);
$dollar = str_replace(".","",$dollar);
echo $dollar;//should print 234323
?>

 

I think you can do this as well

 

<?php
$dollar = "$2,343.23";
$replace = array("$",".",",");
$dollar = str_replace($replace,"",$dollar);
echo $dollar;//should print 234323
?>

Using regex you can, since I am not good at regex here is an alternative method.

 

<?php
    $number = '$2,343.23';
    $number = str_replace('$', '', $number);
    $number = str_replace('.', '', $number);
    $number = str_replace(',', '', $number);
    echo $number;
?>

 

Not the best, but yea without learning regex it works =).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.