Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting ’ instead of an apostrophe(') in PHP

I've tried converting the text to or from utf8, which didn't seem to help.

I'm getting:

"It’s Getting the Best of Me" 

It should be:

"It’s Getting the Best of Me" 

I'm getting this data from this url.

like image 768
Mint Avatar asked Feb 18 '10 20:02

Mint


People also ask

What is â € TM?

html - An apostrophe is rendering as â€tm.

What is this character â?

Â, â (a-circumflex) is a letter of the Inari Sami, Skolt Sami, Romanian, and Vietnamese alphabets. This letter also appears in French, Friulian, Frisian, Portuguese, Turkish, Walloon, and Welsh languages as a variant of the letter "a". It is included in some romanization systems for Persian, Russian, and Ukrainian.

Why does É become Ã?

This typically) happens when you're not decoding the text in the right encoding format (probably UTF-8).


2 Answers

To convert to HTML entities:

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

See docs for mb_convert_encoding for more encoding options.

like image 180
Matthew Avatar answered Sep 28 '22 01:09

Matthew


Make sure your html header specifies utf8

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 

That usually does the trick for me (obviously if the content IS utf8).

You don't need to convert to html entities if you set the content-type.

like image 33
Ben Avatar answered Sep 28 '22 01:09

Ben