Jump to content

[SOLVED] string replace


jakebur01

Recommended Posts

I am trying to get just the number from the following. $25.600 (EA) or $12,452.58(EA) or $254.600 (EA) or $25.64EA

 

All I am wanting is the number without the characters or commas. Ex.  25.60 or 12452.58

 

Would it be something like this?

 $targetChars3=array('"', '$', ',','a','b','c','d',e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','(',')','&','#','%','^');
   $listprice=str_replace($targetChars3, "", $listprice);

 

Link to comment
Share on other sites

try this

 

$price  = $price_here; //i.e. $12,452.58(EA)
$to_remove = array("$",".", ",", "(EA)");
$to_put_in   = array("","","","");

echo str_replace($to_remove,$to_put_in,$price) ;

 

basicaly replacing characters with "" or nothing...let me know how it goes....i tested it myself and it works

Link to comment
Share on other sites

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.