0

I am working with a wordpress project. where using some money related work. where amount in database.the amount shows with a $ sign. i want to replace this $ sign with EURO sign. but when i using str_replace function it took the $amount as a variable, not as a string. what is the way to replace this $ ?

Here echo product_list_price($project->ID); function returning the price containing $ sign. now i have to replace this sign into EURO sign and then to echo. how can i convert this as a single quoted string?

Thanks in advance

Shahadat Atom
  • 314
  • 2
  • 13

2 Answers2

3

$euroPrice = str_replace('$', '€', $dollarPrice);

As mentioned here, PHP tries to interpret words starting with $ inside double-quoted strings as variables.

BVengerov
  • 2,947
  • 1
  • 18
  • 32
1

The works fine, str_replcae will give you new modified string that you need to store, the old one will not be modified

    <?php
$money="44$";
$money2='44$';
$m1 = str_replace("$","€",$money);
$m2 =str_replace("$","€",$money2);
$m3 = str_replace('$','€',$money2);
echo $money." ".$money2." ";
echo $m1." ".$m2." ".$m3;
?>

output:

44$ 44$ 44€ 44€ 44€
Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
  • Its not working brother. as the amount is return of function . – Shahadat Atom Aug 24 '16 at 05:25
  • 1
    liked i show the proper running example with output , so must be doing something else so we need to take a look what actually you are trying to achieve or there could be some compatible code or bug something. – Pavneet_Singh Aug 24 '16 at 05:28