UTF-8下的PHP全角标点转为半角

来源:互联网 发布:网络上有重名 编辑:程序博客网 时间:2024/06/06 08:46
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>  
 
<?php  
    $str = "0123ABCDFWS\",.?<>{}[]*&^%#@!~()+-|:;";  
    echo "$str";  
    echo "<br />";  
    $str = iconv('utf-8', 'gbk', $str);
    @$str = preg_replace('/\xa3([\xa1-\xfe])/e', 'chr(ord(\1)-0x80)', $str);  
    echo $str;