-2

I am going to use a class to filter out symbols I don't want.
so form one page I send the value i want to filter to a php page were it get filtered. I have used preg_replace to filter all the symbols but the euro sign.

When I put the euro sign in I get â¬

I have used...;

header('Content-Type: text/html; charset=utf-8'); on both pages

and

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

on the main page.

What am I doing wrong?

Damien Pirsy
  • 25,319
  • 8
  • 70
  • 77
  • 2
    Please provide an actual code sample of what exactly you're doing. The short answer is you're having an encoding problem. The long answer is impossible to give without more details. – deceze Nov 20 '13 at 11:27
  • 1
    One thing that's for sure is that a UTF-8 encoded "€" is being interpreted as ISO-8859 here. Why exactly that is and where it happens is impossible to say. – deceze Nov 20 '13 at 11:37

1 Answers1

-2

Use utf8_decode() function.

utf8_decode("â¬")

Will output €

PROOF HERE: http://www.cafewebmaster.com/online_tools/utf_decode

Have a try

Kevin Cittadini
  • 1,449
  • 1
  • 21
  • 30
  • 1
    Despite the person posing the question not providing many details, one thing the do state is that they are outputting a header stating the content is utf-8. Therefore "decoding" the content away from utf-8 is quite unhelpful. Rather they need to find out why their UTF-8 content is being displayed incorrectly despite being described as UTF-8. – Rob Baillie Nov 20 '13 at 11:30
  • 2
    Nope. It totally depends on what encoding "â¬" is in and what encoding the result will be interpreted in. If you need to take that much care of encodings, you may as well do it right without using `utf8_decode`. Please read [What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text](http://kunststube.net/encoding/). – deceze Nov 20 '13 at 11:30
  • I frankly don't know why you also need to kinda "let me feel like I'm not a programmer or I don't know things" - I know that depends on what encoding "â¬" is in ( in fact http://3v4l.org/pW2dG ). Anyway, if it works for the user who posted the question and It's fine with him, It might be a (little of course) help anyway. And that's my purpose, help other programmers. Of course resolving completely the issue would be helpful, I just gave my little help that' all. There's no need to do this. – Kevin Cittadini Nov 20 '13 at 11:37
  • Anyway what @RobBaillie said it's true and I completely agree with it. – Kevin Cittadini Nov 20 '13 at 11:40
  • 1
    I don't know what you know, but the blanket statement you gave as your answer is far from covering the complexity of the topic. It's a lucky bandaid fix which is ignoring the real problem and isn't really advancing the actual understanding of the OP of what's going on here. – deceze Nov 20 '13 at 11:40
  • "a lucky bandaid" - I repeat, there's no need to say these things. It just helped - NOT COMPLETELY - as I also admitted, so why this behaving? Of course I am aware that he has a bigger problem that needs to be fixed so next time, more details = more probability of getting it fixed ( just like you said ) – Kevin Cittadini Nov 20 '13 at 11:42
  • @Peter Yes, exactly. Somewhere your handling of encodings is broken, you need to fix that first. I suggest you read the aforelinked article for starters, perhaps http://stackoverflow.com/questions/279170/utf-8-all-the-way-through next. – deceze Nov 20 '13 at 11:44
  • @Kevin Sorry, but I'm looking at it from the point of view of other random people stumbling across this answer later and applying it to their problems. In this context it really isn't a helpful answer. – deceze Nov 20 '13 at 11:46
  • I have had this problem once before, so I delete the site and started all over again to find out that I have the same problem again..haha – Peter Breuls Nov 20 '13 at 11:47
  • 1
    As @deceze says, (and to a point Kevin says as a caveat), it sounds like you probably have a mish-mash of character set encoding and decoding going on. Fixing the issue with a single statement may fix this single issue, but you'll have another 100 waiting in the sidelines to bite you. It's a band-aid. Read the article posted by deceze then decide what to do. – Rob Baillie Nov 20 '13 at 12:11