如何检查特殊字符 php

php
2022-08-30 14:07:43

可能的重复:
preg_match php 特殊字符

大家好,我想通过使用检查字符串中是否存在这些字符:preg_match

^'£$%^&*()}{@'#~?><>,@|\-=-_+-¬'

请帮忙!


答案 1
<?php

$string = 'foo';

if (preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/', $string))
{
    // one or more of the 'special characters' found in $string
}

答案 2

preg_match('/'.preg_quote('^\'£$%^&*()}{@#~?><,@|-=-_+-¬', '/').'/', $string);


推荐