ashburnham Posted December 21, 2007 Share Posted December 21, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/82658-solved-simple-str_replace-issue/ Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 must be some charset issue use htmlentities instead //database has field called total which has the value £100 $price=htmlentities(mysql_result($result,0,"total")); echo $price; Quote Link to comment https://forums.phpfreaks.com/topic/82658-solved-simple-str_replace-issue/#findComment-420392 Share on other sites More sharing options...
ashburnham Posted December 21, 2007 Author Share Posted December 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/82658-solved-simple-str_replace-issue/#findComment-420398 Share on other sites More sharing options...
jitesh Posted December 21, 2007 Share Posted December 21, 2007 Can't you save "£100" in database ? Later $price=str_replace("£100", "", mysql_result($result,0,"total")); Quote Link to comment https://forums.phpfreaks.com/topic/82658-solved-simple-str_replace-issue/#findComment-420403 Share on other sites More sharing options...
thebadbad Posted December 21, 2007 Share Posted December 21, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/82658-solved-simple-str_replace-issue/#findComment-420404 Share on other sites More sharing options...
ashburnham Posted December 21, 2007 Author Share Posted December 21, 2007 Thanks guys - I'm sure I will get there eventually... Quote Link to comment https://forums.phpfreaks.com/topic/82658-solved-simple-str_replace-issue/#findComment-420407 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.