Thursday, August 28, 2014

String Encoding in PHP

If you are getting รข€™ instead of an apostrophe(') or other junk characters instead of any character, here is the solution for it.

PHP has function:

mb_convert_encoding

It converts string's encoding type to desired type.

If you're getting content from file and printing on site, use below function.


echo mb_convert_encoding(
    file_get_contents('http://www.example.com/xyz.php?show=Surviver&ep=20x02&exact=0'),
    "HTML-ENTITIES",
    "UTF-8"
  );