小编Moh*_*tef的帖子

检测 PHP 中字符串的字符集(UTF-8 或 Windows-1256)


我正在开发基于“简单 HTML DOM ”的脚本,我想在获取 URL 的内部文本后检测字符串的字符集,以使用iconv().
我尝试了很多东西,但没有一个能与Windows-1256.
我尝试过的:-

mb_detect_encoding($content)检测Windows-1256UTF-8
mb_detect_encoding($content, "windows-1256")给出错误Illegal argument

function is_utf8($string) {   
  return preg_match('%^(?:  
  [\x09\x0A\x0D\x20-\x7E] # ASCII  
  | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte  
  | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs  
  | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte  
  | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates  
  | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3  
  | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15  
  | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16  
  )*$%xs', $string);
}
Run Code Online (Sandbox Code Playgroud)

如果字符串不是 UTF-8,则此函数返回“0”,但当字符串为 UTF-8 时,它返回“找不到页面”。我不知道为什么!
我的代码是:

$html = file_get_html($url);
foreach($html->find('div[id=content]') as $element) …
Run Code Online (Sandbox Code Playgroud)

php encoding character-encoding iconv

4
推荐指数
1
解决办法
2万
查看次数

选择列不在另一列中的位置2次

如果我有这样的表称为"表"

+--------------+
| id | c1 | c2 |
+--------------+
| 1  | a  | 0  |
| 2  | b  | 1  |
| 3  | c  | 1  |
| 4  | d  | 2  |
| 5  | e  | 2  |
| 6  | f  | 3  |
| 7  | g  | 4  |
| 8  | h  | 5  |
+--------------+
Run Code Online (Sandbox Code Playgroud)

我想选择''''''''''''''''''''''''''''''''''''''''''''''''

mysql sql

2
推荐指数
1
解决办法
313
查看次数

标签 统计

character-encoding ×1

encoding ×1

iconv ×1

mysql ×1

php ×1

sql ×1