joethetree Posted August 14, 2011 Share Posted August 14, 2011 Hey, I've been obsessing over this for hours now, probably have just missed something simple. But. I've got a file saved in a mysql DB - which I'm then opening and echoing. When it gets uploaded the euro sign '€' gets turned into this: '€' (without quotes). So I thought "great, I'll just str_replace() it". I tried this on a test script, and it worked. However, when I went to add this to my main script - it didn't work. str_replace just won't replace it. strpos() won't find it either. Anyone got any ideas? I just can't see what I'm doing wrong. The code: $script = $row['script']; //from sql $script = str_replace(array("€","£"),array("€",'"'),$script); echo $script; Thanks tree Quote Link to comment https://forums.phpfreaks.com/topic/244774-mine-blown/ Share on other sites More sharing options...
ignace Posted August 14, 2011 Share Posted August 14, 2011 You can str_replace all you want until you'll have to deal with the truth: encoding. Don't plan around the problem, solve it. Obviously you are reading the file in a different encoding than the encoding your database is using to store the data. Find out in what encoding the file was written and adjust your database table accordingly. Quote Link to comment https://forums.phpfreaks.com/topic/244774-mine-blown/#findComment-1257313 Share on other sites More sharing options...
xyph Posted August 14, 2011 Share Posted August 14, 2011 UTF-8 FOR EVERYTHING!!! Quote Link to comment https://forums.phpfreaks.com/topic/244774-mine-blown/#findComment-1257315 Share on other sites More sharing options...
sasa Posted August 14, 2011 Share Posted August 14, 2011 you can use iconv() function to convert encoding from UTF-8 to any other i sugest that use UTF-8 in your database Quote Link to comment https://forums.phpfreaks.com/topic/244774-mine-blown/#findComment-1257326 Share on other sites More sharing options...
joethetree Posted August 14, 2011 Author Share Posted August 14, 2011 Turns out the problem was that notepad++ was in ANSI/UTF-8 instead of normal ANSI, changed it and it worked. Though yes, I do need to address the problem before its made instead of creating a hacky fix. UTF-8 for databases, yeah? Also, how do I go about backing up a database? Thanks everyone for your replies Quote Link to comment https://forums.phpfreaks.com/topic/244774-mine-blown/#findComment-1257333 Share on other sites More sharing options...
ignace Posted August 15, 2011 Share Posted August 15, 2011 SELECT .. INTO OUTFILE is just one way of backing-up your database. You could also use replication.. but that may be a little far fetched at this point. There is an article in the MySQL manual. Quote Link to comment https://forums.phpfreaks.com/topic/244774-mine-blown/#findComment-1257595 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.