0

I am trying make some changes in a php code -

Below line

<meta itemprop="price" content="<?php echo $special; ?>"/>

shows up like this in HTML

<meta itemprop="price" content="£32.12"/>

I need to remove this Pound("£") sign from the output. How can I use replace function in this code or there is some other way to do it.

Can someone advise?

8
  • 2
    So, did you try to str_replace it? Commented May 3, 2016 at 21:37
  • tried this - <meta itemprop="price content="<?php echo str_replace($special, '£','') ?>"/> it's not printing anything in this case. Commented May 3, 2016 at 21:39
  • 3
    £ = POUND, € = EURO Commented May 3, 2016 at 21:39
  • 2
    str_replace( '£', '', $special ) Commented May 3, 2016 at 21:40
  • 1
    well all theses answers are the ambulance at the bottom of the cliff - why not stop it being added in the first place Commented May 3, 2016 at 21:53

3 Answers 3

1

Use this:

<?php
//  REMOVES ONLY BRITISH CURRENCY: £ 
<meta itemprop="price" content="<?php echo str_replace('£', '', $special); ?>"/>

OR this:

//  REMOVES CURRENCIES LIKE £, $ & € 
<meta itemprop="price" content="<?php echo preg_replace('&(£|$|€)&', '', $special); ?>"/>
Sign up to request clarification or add additional context in comments.

Comments

1

how do I replace something from a output of PHP function?

Use str_replace

<?php
$special = str_replace("£", "", $special);
?>
<meta itemprop="price" content="<?php=$special;?>"/>

If you need to replace multiple currencies, you can use an array, i.e.:

<?php
$remove = array("£", "€", "$", "₹", "¥", "¢");
$special = str_replace($remove, "", $special);
?>
<meta itemprop="price" content="<?php=$special;?>"/>

Comments

0
<meta itemprop="price" content="<?php echo str_replace("?", "", $special); ?>"/>

1 Comment

Can you expand a little on exactly what this does and how it might answer the OP?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.