Jump to content

[SOLVED] Simple str_replace issue?


ashburnham

Recommended Posts

This is really bugging me - can't figure it out...

 

//database has field called total which has the value £100
$price=str_replace("£", "", mysql_result($result,0,"total"));
//$price now has the value 100

//we now generate a variable $output with all required page output which includes the following line
$output = "£$price";
//and echo this output
echo "$output";

 

Now surely this would echo £100 but the result i'm getting is £?100.

 

Any ideas ???

 

Many thanks...

Link to comment
Share on other sites

I agree that htmlentities is a possible solution but the reason $price is removing the £ sign is that the figure within $price is used elsewhere in the $content and there is one instance that the £ sign needs to be put back on which is where this problem is occuring.

 

I am using £ quite a lot in the script with no problems when it's written as £100 but as soon as it is written as £$price this little ? symbol pops up.

 

So annoying  >:(

Link to comment
Share on other sites

Your code works fine here:

 

<?php
$price = '£100';
$price = str_replace('£', '', $price);
echo "£$price";
?>

 

Outputs

£100 (which translates to £100 in my browser)

 

Try to echo $price after you've extracted it from the database, and then again after removing the pound sign. Pretty sure it's the encoding that's screwed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.