hi all, How can I limit the data accepted into my php script
$username = 'ABC123#!'
Would End Up Being
ABC123
I dont want it to give any errors I just want it to be automatic.
by sharma
Try using regular expressions:
<?php $username = 'ABC123^#!'; $new_name = preg_replace('#[^a-z0-9]#i', '', $username); echo $new_name; ?>
Hi its working fine but, why # and #i used. please could you explain that.
<?php
$username = 'ABC123#!'; $new_name = preg_replace('#[a-z0-9]#i', '', $username);
echo $new_name;
?> bye sharma
The # is used to decide where the pattern for the expression start and end. The i is a pattern modifier that tells the function to do a case-insensitive search.