php实现正则替换特殊符号的方法:首先创建一个PHP示例文件;然后通过正则表达式“preg_replace($regex,"",$other);”实现正则替换特殊符号即可。
本文操作环境:windows7系统、PHP7.1版,DELL G3电脑
如果是只想输入中文的话,就这么写,要注意是分gb2312和utf-8的哦:
gb2312:if(!preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/",$str)) utf-8 :if(!preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$str))
去除特殊字符
$regex = "/(\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\|\||\"){2,}/"; $other = preg_replace($regex,"",$other); $regex = "/(,|。|!|;|:|、|’|‘|【|】|《|》|?|@|#|¥|%|&|\*|(|)|\-|\+|\=|@|…){2,}/"; $other = preg_replace($regex,"",$other);
推荐学习:《PHP视频教程》
The above is the detailed content of How to implement regular replacement of special symbols in PHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
