c_pattle Posted September 23, 2011 Share Posted September 23, 2011 When getting data from a database I'm trying to use the str_replace function to get rid of any pound signs but it doesn't seem to be working. My code is below. str_replace("£", "", $array['product_price']) I've also tried replace "£" with "£" but that doesn't work either. Does anyone know why that's happening? Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/247727-str_replace-problem/ Share on other sites More sharing options...
Pikachu2000 Posted September 23, 2011 Share Posted September 23, 2011 Maybe it isn't actually stored in the field with the numeric value? If it is, it really shouldn't be anyhow. No way to tell for sure without seeing more of the code, though. Link to comment https://forums.phpfreaks.com/topic/247727-str_replace-problem/#findComment-1272119 Share on other sites More sharing options...
c_pattle Posted September 23, 2011 Author Share Posted September 23, 2011 I checked and it is stored in the same field. Also if I try to use the same code on a post variable so that I remove the "£" before it gets entered into the database it still doesn't seem to remove it. So if I did the following it doesn't work. $products->product_price = str_replace("£", "", $_POST['product-price']); Link to comment https://forums.phpfreaks.com/topic/247727-str_replace-problem/#findComment-1272171 Share on other sites More sharing options...
requinix Posted September 23, 2011 Share Posted September 23, 2011 It may be the entity £ or in a text encoding other than what your file is written in. Link to comment https://forums.phpfreaks.com/topic/247727-str_replace-problem/#findComment-1272181 Share on other sites More sharing options...
c_pattle Posted September 23, 2011 Author Share Posted September 23, 2011 Thanks. How do I found out how it's encoded? Link to comment https://forums.phpfreaks.com/topic/247727-str_replace-problem/#findComment-1272193 Share on other sites More sharing options...
requinix Posted September 23, 2011 Share Posted September 23, 2011 What does echo bin2hex($array["product_price"]); output? Link to comment https://forums.phpfreaks.com/topic/247727-str_replace-problem/#findComment-1272199 Share on other sites More sharing options...
c_pattle Posted September 23, 2011 Author Share Posted September 23, 2011 If the contents of the field is just "£" it outputs "a3" Link to comment https://forums.phpfreaks.com/topic/247727-str_replace-problem/#findComment-1272201 Share on other sites More sharing options...
requinix Posted September 24, 2011 Share Posted September 24, 2011 Instead of typing a pound sign in your PHP script, try \xA3. str_replace("\xA3", "", $_POST['product-price']); Or change your file encoding to ISO 8859-1/Latin1. Link to comment https://forums.phpfreaks.com/topic/247727-str_replace-problem/#findComment-1272211 Share on other sites More sharing options...
c_pattle Posted September 24, 2011 Author Share Posted September 24, 2011 Awesome, that worked. Thanks! Link to comment https://forums.phpfreaks.com/topic/247727-str_replace-problem/#findComment-1272318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.