How to convert full-width symbols to half-width symbols in PHP

藏色散人
Release: 2023-03-08 18:14:02
Original
2615 people have browsed it

php实现全角符号转半角的方法:首先创建一个PHP示例文件;然后定义一个“SBC_DBC($str,$args2=1) {...}”方法;最后通过“str_replace($DBC,$SBC,$str);”方式实现全角转半角即可。

How to convert full-width symbols to half-width symbols in PHP

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑

PHP 全角和半角转换函数

代码如下:

', '"', '\'','?',
'[', ']', '{', '}', '\\',
'|', '+', '=', '_', '^',
'$', '~', '`'
);
if($args2==0)
return str_replace($SBC,$DBC,$str);  //半角到全角
if($args2==1)
return str_replace($DBC,$SBC,$str);  //全角到半角
else
return false;
}
/*
$str = "alskdf";
echo $str;
echo "
"; echo SBC_DBC($str,0); echo SBC_DBC($str,1); */ ?>
Copy after login

推荐学习:《PHP视频教程

The above is the detailed content of How to convert full-width symbols to half-width symbols in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!