Skip to content
Advertisement

How to check control keys within string by php

I have string as below:

  • abccdefx7f (notice that the ‘x7f’ is Del key on keyboard) I want to check if the above string has control key or not ?

Control keys include: Del, Tab, Esc, F1 ~ F12, Shift,….

Please help me the solution, I am using PHP code.

Advertisement

Answer

There,

You can use the phps ctype extension there are many functions to do your stuff.

For Exmaple you can use ctype_print() function which Checks all chars if there printable as cntrl chars aren’t printable it should help you.

$x = "asbahsdbx7f";
$y = "JustText";

var_dump(
  ctype_print($x), // False
  ctype_print($y)  // True
);

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement