从字符串中删除€符号[重复]

问题描述:

This question already has an answer here:

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?

</div>

此问题已经存在 这里有一个答案: p>

  • 如何在PHP中替换部分字符串? [复制] 5 answers span> li> \ n ul> div>

    我使用此代码显示Magento商店内的价格: p>

     &lt;?php  
     
     $ myPrice = $ _coreHelper-&gt; formatPrice($ _ price + $ _weeeTaxAmount,false); 
     $ zeros = substr($ myPrice,-2); 
     
     if(strval($ zeros)==  “00”){
     $ myPrice = substr($ myPrice,0,-2); 
     $ myPrice = $ myPrice。  ' - '; 
    } 
     
     echo'&lt; span class =“price”&gt;'。$ myPrice。'&lt; / span&gt;'; 
     
    ?&gt; 
      code>  
     
     

    但我也想从这个字符串中删除€符号。 p>

    我该如何解决? p> div>

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>'; 
?>

Use php str_replace :-

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

This function is binary-safe

str_replace(find,replace,string,count)