Getting ’ instead of an apostrophe(') in PHP

前端 未结 14 926
慢半拍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:19

    If you're here because you're experiencing issues with junk characters in your WordPress site, try this:

    1. Open wp-config.php

    2. Comment out define('DB_CHARSET', 'utf8') and define('DB_COLLATE', '')

      /** MySQL hostname */
      define('DB_HOST', 'localhost');
      
      /** Database Charset to use in creating database tables. */
      //define('DB_CHARSET', 'utf8');
      
      /** The Database Collate type. Don't change this if in doubt. */
      //define('DB_COLLATE', '');
      
    0 讨论(0)
  • 2020-11-27 03:20

    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.

    0 讨论(0)
  • 2020-11-27 03:22

    I looked at the link, and it looks like UTF-8 to me. i.e., in Firefox, if you pick View, Character Encoding, UTF-8, it will appear correctly.

    So, you just need to figure out how to get your PHP code to process that as UTF-8. Good luck!

    0 讨论(0)
  • 2020-11-27 03:23

    You Should check encode encoding origin then try to convert to correct encode type.

    In my case, I read csv files then import to db. Some files displays well some not. I check encoding and see that file with encoding ASCII displays well, other file with UTF-8 is broken. So I use following code to convert encoding:

    if(mb_detect_encoding($content) == 'UTF-8') {
        $content = iconv("UTF-8", "ASCII//TRANSLIT", $content);
        file_put_contents($file_path, $content);
    } else {
        $content = mb_convert_encoding($content, 'UTF-8', 'UTF-8');
        file_put_contents($file_path, $content);
    }
    

    After convert I push the content to file then process import to DB, now it displays well in front-end

    0 讨论(0)
  • 2020-11-27 03:25

    try this :

    html_entity_decode(mb_convert_encoding(stripslashes($text), "HTML-ENTITIES", 'UTF-8'))
    
    0 讨论(0)
  • 2020-11-27 03:26

    It sounds like you're using standard string functions on a UTF8 characters (’) that doesn't exist in ISO 8859-1. Check that you are using Unicode compatible PHP settings and functions. See also the multibyte string functions.

    0 讨论(0)
提交回复
热议问题