The solution of reading TXT Chinese chaotic code by PHP

time:17-06-28 forum:PHP tools and code
  https://my.oschina.net/landry17h/blog/17145

you need to read a TXT file using PHP because of business requirements, but there is a nauseous code problem on the issue of design to Chinese; First look at the encoding format of TXT: ANSI, Unicode, Unicode Big Endian, UTF-8

1. Code format, but it can be used instead of ANSI and UTF-8 format;

2, so for this problem, a special conversion is made:
[code]
$str = mb_convert_encoding ($str,'UTF-8','Unicode'); Break.



complete code as follows:
[code]
if ($fname = $_FILES.#91;'nickname'.#93;.#91; > / / / > $= = = = = $= $ Contents, array ('GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII');


; / / / / / > $num;

$str = trim (fgets ($fp));

if ($encoding! = false). Text = $str;

}

}

else {

$str = > = $str;

}

}

}

while (! (feof ($fp)). $str = iconv ($encoding,'UTF-8', $str);

if ($str! =.Quot;.Quot; and). $str = mb_convert_encoding ($str,'UTF-8','Unicode');

if ($str! =.Quot;.Quot; and). Ode]

prev:Ma Chenchen: she must be an old godmothe... next:Processing method of Chinese characters ...
post comment
Notice



approved   Brachless college students play game...   The most inspirational live street "...   Ji'nan old shoemaker has made more t...   Ji'nan auxiliary police "storm" Engl...   Australian 16 year old girl, driving...
rand   Eliminate 3 Chinese characters from ...   Importing large databases to virtual...   Using regular expressions to verify ...   Regular string replacement and parti...   PHP determines the character functio...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com