You might also rarely use this, but I certainly need it at some point to check for not-allowed characters etc.
In this example I also added German umlauts.
$my_string = $_POST['some_textfield_to_check'];
$my_array = str_split($my_string);

// create the character set
$german = str_split('ÄÖÜäöüß');
$chars = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9), $german);

for ($i=0, $i<count($my_array), $i++) if (!in_array($my_array[$i], $chars)) echo 'not allowed';

Alternative, string-based check (probably less consuming for long texts):
$chars_str = implode('', $chars);

for ($i=0, $i<count($my_array), $i++) if (strpos($chars_str, $my_array[$i]) === false) echo 'not allowed';

Of course PREG_MATCH will also do the job and uses the least code, but probably the most cpu:
if (preg_match('/[^A-Za-z0-9ÄÖÜäöüß]/', $my_string, $match)) {
  echo 'something not allowed:';
  print_r($match);
}
sara on Feb 19, 2019, 12:24 pm:
thank you
www.ju.edu.jo
Enter your comment:


  Use [code=LANGUAGE]...[/code] for highlighting (i.e. html, php, css, js)