大家好,今天小热关注到一个比较有意思的话题,就是关于mb_detect_encoding的问题,于是小编就整理了3个相关介绍mb_detect_encoding的解答,让我们一起看看吧。
文章目录:
一、Call to undefined function mb_detect_encoding() 错误怎么解决?_百度...
应该是配置php.ini出错了,找到“ ; extension_dir = “ext” ”,在它下面添加如下代码:
; 指定 PHP 扩展库的路径,你解压的实际路径
extension_dir = “d:/php/ext”
二、求个简单的php代码
_tags($string, $replace_with_space = true)
{
if ($replace_with_space) {
return preg_replace('!<[^>]*?>!', ' ', $string);
} else {
return strip_tags($string);
}
}
截取字符函数(匹配各种编码)
function truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false){
if ($length == 0)
return '';
if (is_callable('mb_strlen')) {
if (mb_detect_encoding($string, 'UTF-8, ISO-8859-1') === 'UTF-8') {
// $string has utf-8 encoding
if (mb_strlen($string) > $length) {
$length -= min($length, mb_strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length + 1));
}
if (!$middle) {
return mb_substr($string, 0, $length) . $etc;
} else {
return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, - $length / 2);
}
} else {
return $string;
}
}
}
// $string has no utf-8 encoding
if (strlen($string) > $length) {
$length -= min($length, strlen($etc));
if (!$break_words && !$middle) {
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
}
if (!$middle) {
return substr($string, 0, $length) . $etc;
} else {
return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
}
} else {
return $string;
}
}
综合就是
$arc=strip_tags($arc);
$arc=truncate($arc,200)
三、PHP怎么解析微信支付结果返回的xml
PHP解析微信支付结果返回的xml的方法是通过自定义方法和第三方组件DomDocument实现的。
1、解析代码如下:
<?PHP
header("Content-type:text/html; Charset=utf-8");
$url = ";;
// 加载XML内容
$content = file_get_contents($url);
$content = get_utf8_string($content);
$dom = DOMDocument::loadXML($content);
/*
此处也可使用如下所示的代码,
$dom = new DOMDocument();
$dom->load($url);
*/
$elements = $dom->getElementsByTagName("current_conditions");
$element = $elements->item(0);
$condition = get_google_xml_data($element, "condition");
$temp_c = get_google_xml_data($element, "temp_c");
echo '天气:', $condition, '<br />';
echo '温度:', $temp_c, '<br />';
function get_utf8_string($content) { // 将一些字符转化成utf8格式
$encoding = mb_detect_encoding($content, array('ASCII','UTF-8','GB2312','GBK','BIG5'));
return mb_convert_encoding($content, 'utf-8', $encoding);
}
function get_google_xml_data($element, $tagname) {
$tags = $element->getElementsByTagName($tagname); // 取得所有的$tagname
if ($items->length > 1) {
return $items;
}
$tag = $tags->item(0); // 获取第一个以$tagname命名的标签
if ($tag->hasAttributes()) { // 获取data属性
$attribute = $tag->getAttribute("data");
return $attribute;
}else {
return false;
}
}
?>
2、返回支付的xml报文:
<?xml version="1.0"?>
<xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<forecast_information>
<city data="Shenzhen, Guangdong"/>
<postal_code data="shenzhen"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2009-10-05"/>
<current_date_time data="2009-10-04 05:02:00 +0000"/>
<unit_system data="US"/>
</forecast_information>
<current_conditions>
<condition data="Sunny"/>
<temp_f data="88"/>
<temp_c data="31"/>
<humidity data="Humidity: 49%"/>
<icon data="/ig/images/weather/sunny.gif"/>
<wind_condition data="Wind: mph"/>
</current_conditions>
</weather>
</xml_api_reply>
3、打印解析结果:
print $html;
到此,以上就是小编对于mb_detect_encoding的问题就介绍到这了,希望介绍关于mb_detect_encoding的3点解答对大家有用。
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。