0

I use this code to display price inside a Magento shop:

<?php

    $myPrice = $_coreHelper->formatPrice($_price + $_weeeTaxAmount, false);
    $zeros = substr($myPrice, -2);

    if(strval($zeros) == "00") {
        $myPrice = substr($myPrice, 0, -2);
        $myPrice = $myPrice . '-';
    }

    echo '<span class="price">'.$myPrice.'</span>';

?>

But I also want to remove the € sign from this string.

How can I fix that?

Rizier123
  • 58,877
  • 16
  • 101
  • 156
JGeer
  • 1,768
  • 1
  • 31
  • 75

2 Answers2

5

str_replace($search,$replace,$string) might be the function you are looking for.

take a look at this line of code:

$myPrice = str_replace("€","",$myPrice);

this will search the string for € and replace it with an empty string, which means it removes the €.

refer to the php documentation for further information. i.e. you can also use arrays for $search and $replace (examples in the php doc)

full example:

<?php 
$myPrice = $_coreHelper->formatPrice($_price + $_weeeTaxAmount, false);
$zeros = substr($myPrice, -2);
if(strval($zeros) == "00") { $myPrice = substr($myPrice, 0, -2);
$myPrice = $myPrice . '-'; }

$myPrice = str_replace("€","",$myPrice);
//or if the € is htmlencoded
$myPrice = str_replace("&euro;","",$myPrice);

echo '<span class="price">'.$myPrice.'</span>'; 
?>
Tanuel Mategi
  • 1,253
  • 6
  • 13
  • Thanks! The price is now displayed with a space ( ) in front. How can I remove that space? – JGeer Oct 21 '15 at 13:01
  • use [str_replace](http://php.net/manual/en/function.str-replace.php) ;) like this: `$myPrice = str_replace(" ","",$myPrice);` – Tanuel Mategi Oct 21 '15 at 13:02
0

Use php str_replace :-

str_replace("€","",$yourstring);

This function is binary-safe

str_replace(find,replace,string,count)
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20