arrays - PHP: Check if special characters from a list are present in a string -
this newbie question.
let's have array of illegal characters, i.e.:
$special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}"); i need check if of these characters present in string, i.e.
$my_string = "abcde!fgh" i have googled solution in simple manner haven't found satisfactory answer.
any on appreciated.
a concise way 2 data structures be:
count( array_intersect( str_split($my_string), $special_chars ) ) that tell how many of special characters in string.
you otherwise write loop character list , manually probe strpos.
the least effort converting special character list regex charclass , testing against string.
Comments
Post a Comment