Hi.
I have a string, but i want to check if the chars of the string are all valid, because the string can't contain certain chars, so is there any way that i define the chars that the string is possible to contain and then compare with the string and get false or true if th string is ok or if she got wrong chars?
With the best regards
Hugo Gomes
checking a string
Moderator: General Moderators
- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
Check out preg_match()
I can't use preg_match() 
Code: Select all
function checkCharacters($text)
{
$allowed = "1=2=3=4=5=6=7=8=9=0=q=w=e=r=t=y=u=i=o=p=a=s=d=f=g=h=j=k=l=z=x=c=v=b=n=m=.=(=)= =,=-=_=;=:=?=!";
$arr = explode("=", $allowed);
sort ($arr);
for ($i = 0; $i <= strlen($text); $i++)
{
$letter = strtolower(substr($text, $i, 1));
if (!in_array($letter, $arr))
{
return false;
}
}
return true;
}- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact: