lau*_*kok 28 php special-characters iconv
我还是不明白是怎么iconv运作的.
例如,
$string = "Löic & René";
$output = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $string);
Run Code Online (Sandbox Code Playgroud)
我明白了
注意:iconv()[function.iconv]:检测到输入字符串中的非法字符...
$string = "Löic"; 要么 $string = "René";
我明白了
注意:iconv() [function.iconv]: 在输入字符串中检测到不完整的多字节字符.
我一无所获 $string = "&";
我需要将两组不同的输出存储在数据库表的两个不同列中,
我需要转换Löic & René到Loic & Rene清洁网址的目的.
我需要保持原样 - Löic & René因为Löic & René只有htmlentities($string, ENT_QUOTES);在我的html页面上显示它们时才转换它们.
我尝试了下面的php.net中的一些建议,但仍然无法正常工作,
我有一种情况,我需要一些字符音译,但其他人忽略了(对于像ayn或hamza这样奇怪的变音符号).添加// TRANSLIT // IGNORE似乎对我有用.它可以音译所有能够音译的内容,但随后却抛弃了无法实现的内容.
所以:
$string = "?ABB?S?B?D";
echo iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $string);
// output: [nothing, and you get a notice]
echo iconv('UTF-8', 'ISO-8859-1//IGNORE', $string);
// output: ABBSBD
echo iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $string);
// output: ABBASABAD
// Yay! That's what I wanted!
Run Code Online (Sandbox Code Playgroud)
另一个,
Andries Seutens 07-Nov-2009 07:38
When doing transliteration, you have to make sure that your LC_COLLATE is properly set, otherwise the default POSIX will be used.
To transform "rené" into "rene" we could use the following code snippet:
setlocale(LC_CTYPE, 'nl_BE.utf8');
$string = 'rené';
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
echo $string; // outputs rene
Run Code Online (Sandbox Code Playgroud)
我怎么能真正解决它们?
谢谢.
编辑:
这是我测试代码的源文件,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" class="no-js">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<?php
$string = "Löic & René";
$output = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $string);
?>
</html>
Run Code Online (Sandbox Code Playgroud)
小智 23
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', utf8_encode($s));
Run Code Online (Sandbox Code Playgroud)
wim*_*vds 14
你用UTF-8编码保存你的源文件了吗?如果不是(我猜你没有,因为那将产生"不完整的多字节字符"错误),然后先尝试.
| 归档时间: |
|
| 查看次数: |
66797 次 |
| 最近记录: |