php

PHP Remove Pound Sign (£) from price


I have price value which has pound sign in front of it. I need to remove that sign.

$price = '£3.76' (This comes from database and is stored as a string within the database)

1) preg_replace('/[\£]/', '', $price);
2) ltrim($price, '£');
3) str_replace(utf8_decode("£"),"",utf8_decode($price));
4) str_replace('£', '', $price);

I tried to use everything about but nothing worked. 1 and 4 replaces with  and 2 and 3 adds  to the left of the value. Can someone please help me.


Solution

  • I have had a similar situation. Try the following code:

    $amount = "$500";
    
    echo substr($amount,1,strlen($amount)); // returns "500"