Page 1 of 1

Special Characters

Posted: Sat Aug 13, 2005 2:42 am
by quadoc
Is there a way that PHP can intercepts keyboard inputs. I'm try to produce special characters when a user type a combination of keys. For example, if the user type a' , have the output display á, or if the user type e^ , have the output display ê . Does anyone have any tips? Thanks... :?

Posted: Sat Aug 13, 2005 3:26 am
by s.dot
If you're wanting to do this on the page before it's submitted, you'd have to use a client side language, as PHP wouldn't handle it.

If you're wanting to change the input into a different character set, I found the functions iconv() and recode_str().

If you're just wanting to change a set of certain characters, like your example, str_replace would be suitable.

Code: Select all

$data = $_POST['data'];

$combinations = array("e^","a'","etc");
$replacements = array("specialchar1","specialchar2","etc");

// sorry, I don't know how to do the special characters 

$newdata = str_replace($combinations,$replacements,$data);

Posted: Mon Aug 15, 2005 1:30 pm
by quadoc
Thanks for the tips. But I've found out that there is a onkeyup even handler that you can use with the form.