Getting ’ instead of an apostrophe(') in PHP

前端 未结 14 1031
慢半拍i
慢半拍i 2020-11-27 02:38

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 sho

14条回答
  •  广开言路
    2020-11-27 03:27

    I know the question was answered but setting meta tag didn't help in my case and selected answer was not clear enough, so I wanted to provide simpler answer.

    So to keep it simple, store string into a variable and process that like this

    $TVrageGiberish = "It’s Getting the Best of Me";
    
    $notGiberish = mb_convert_encoding($TVrageGiberish, "HTML-ENTITIES", 'UTF-8');
    
    echo $notGiberish;
    

    Which should return what you wanted It’s Getting the Best of Me

    If you are parsing something, you can perform conversion while assigning values to a variable like this, where $TVrage is array with all the values, XML in this example from a feed that has tag "Title" which may contain special characters such as ‘ or ’.

    $cleanedTitle = mb_convert_encoding($TVrage->title, "HTML-ENTITIES", 'UTF-8');
    

提交回复
热议问题