How to check if string contains special characters in PHP

1 Answer

0 votes
$string = 'php c++ c c# java';

if (preg_match('/[`!@#$%^&*()_+\-=\[\]{};\':"\\|,.<>\/?~]/', $string)) {
    echo "yes";
} else {
    echo "no";
}




/* 
run:

yes

*/

 



answered Feb 14, 2022 by avibootz

Related questions

1 answer 225 views
1 answer 251 views
1 answer 326 views
1 answer 274 views
1 answer 212 views
1 answer 231 views
...