php 5.2.4 iconv函数TRANSLIT 有时候不靠谱
php 5.2.4 iconv函数TRANSLIT 有时不靠谱
php 版本 5.2.4
问题:文件字符串转码时按字节截断不当
比如
$str = “公司”; //默认以UTF-8编码$str = Simple_Util_String::msubstr($str, 4); // 按字节截取前4个字节,原字符串有6个字节$str .= “adfadsfasdfadsfasdf”; //拼接后面的字符串 (执行下一步后,这些字符就消失了)$str = iconv("UTF-8", "GBK//TRANSLIT",$str); // 转码 , 遇到不认识的字符串进行转写
执行此步时,“公司”的“司”字编码不完整,iconv不认识,但iconv没有转写,而是做了截断。导致$str后面的字符串也没有转换成功,“adfadsfasdfadsfasdf”丢失了。在一些商业产品,尤其是有关统计的系统里,这是很危险的。
解决方法是:
改变iconv第二个参数。
$str = iconv("UTF-8","GBK//IGNORE", $str);
总结:iconv的TRANSLIT并不靠谱,遇到不认识也不能转写的字符串,也可能截断。保险的方法是用IGNORE。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In the process of text processing, it is a common requirement to convert strings in different encoding formats. The iconv (InternationalizationConversion) function provided in the PHP language can meet this need very conveniently. This article will introduce the use of iconv function in detail from the following aspects: Definition of iconv function and introduction to common parameters Example demonstration: Convert GBK encoded string to UTF-8 encoded string Example demonstration: Convert UTF

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

iconv-fencoding[-tencoding][inputfile]...[Function] Converts the contents of a given file from one encoding to another. [Description]-fencoding: Convert characters from encoding to encoding. -tencoding: Convert characters to encoding. -l: List the known set of encoded characters -ofile: Specify the output file -c: Ignore illegal characters in the output -s: Suppress warning messages, but not error messages --verbose: Display progress information -f and -t can The specified legal characters are listed in the command with the -l option. [Example]* List currently supported character encodings

1The basic unit of Unicode computer storage is the byte, which is composed of 8 bits. Since English only consists of 26 letters plus a number of symbols, English characters can be stored directly in bytes. But other languages (such as Chinese, Japanese, Korean, etc.) have to use multiple bytes for encoding due to the large number of characters. With the spread of computer technology, non-Latin character encoding technology continues to develop, but there are still two major limitations: no multi-language support: the encoding scheme of one language cannot be used in another language and there is no unified standard: for example There are many encoding standards in Chinese such as GBK, GB2312, GB18030, etc. Since the encoding methods are not unified, developers need to convert back and forth between different encodings, and many errors will inevitably occur.

What are the similarities and differences between __str__ and __repr__? We all know the representation of strings. Python's built-in function repr() can express objects in the form of strings to facilitate our identification. This is the "string representation". repr() obtains the string representation of an object through the special method __repr__. If __repr__ is not implemented, when we print an instance of a vector to the console, the resulting string may be. >>>classExample:pass>>>print(str(Example()))>>>

图片消失如何解决先是图片文件上传$file=$_FILES['userfile']; if(is_uploaded_file($file['tmp_name'])){$query=mysql_query("INSERT INTO gdb_banner(image_src ) VALUES ('images/{$file['name'

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没问题。
