想要获取HTML源代码META部分的编码部分 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
……
就是要获取charset后面的utf-8、gb2312等编码部分
最好再注释一下代码,授人以渔嘛
谢谢!
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
……
就是要获取charset后面的utf-8、gb2312等编码部分
最好再注释一下代码,授人以渔嘛
谢谢!
<?php
$str = <<<STR
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
STR;
preg_match_all("/<[^>].*charset=(.*)\"/im", $str, $matches);
var_dump($matches[1]);
?>