Search code examples
phphtmlcharacter-encodingcharacterspecial-characters

How to remove unnecessary characters from string?


There is a problem in character when I fetch data from database.

doesn�t

It�s

I have tried to remove it using str_replace function but it's not working.

str_replace('�','',$str);

The encoding is

<meta charset="UTF-8" /> 

How can i solve these problem?


Solution

  • Try utf8_encode() function.

    It will remove that characters

    utf8_decode('doesn�t');  // doesnt
    

    this is not good because it removes ' from doesn't

    OR

    Just update your Meta tag

    <meta charset="UTF-8" />
    

    to

    <meta charset="ISO-8859-1" />
    

    Output

    doesn't

    It's