Questions about beginner transcoding

Source: Internet
Author: User
New hand conversion code question: urltest.txt; $ read & nbsp; fopen ($ url, r) & nbsp; or & nbsp; die (opening failed); $ textfread ($ read, 100 ); fclose ($ read); echo & nbsp; iconv (UTF-8, GBK, this is a test ). & lt; br & gt; # new-user transcoding problems

Using urlpolic'test.txt ';
$ Read = fopen ($ url, 'r') or die ('open failed ');
$ Text = fread ($ read, 100 );
Fclose ($ read );
Echo iconv ('utf-8', 'gbk', 'This is a test ').'
'; # This sentence is OK
Echo iconv ('utf-8', 'gbk', $ text ).'
'; # This error message


The first echo is normal, and the second echo always reports the following error:
Notice: iconv (): Detected an illegal character in input string

Test.txt is in UTF-8 format.

Share: More


------ Solution --------------------
Echo iconv ('utf-8', 'gbk // IGNORE ', $ text)
// IGNORE can IGNORE the words it does not know and then go down to report no error, // transcoder is to cut off the words it does not know and the content behind it, and report an error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.