Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing in PHP 1

Status
Not open for further replies.

pegazaus

Instructor
Aug 16, 2005
22
SE
Hi

I need to know how to parse a String in PHP.
Exemple when a use enters his/her name, I need a function that checks if the user did type some nonalphabethical characters.
 
What kind of non-alphabetical characters?

Generally, numbers are not part of a name. But apostrophes, spaces, dashes, periods and commas can.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I never bother checking names too strict, as I think of it like this:

if they want to fake it, they will!
sure, you can block them from calling themselves:
bobby19

but, they can use the name:
AkajUjajasdIAkdk AKjajsah

you have no way to check if they input real data, or if they pretend to be george bush..

I think email validation is the only really important thing for me, and this is why I think email activation link might be a good thing.

Olav Alexander Mjelde
Admin & Webmaster
 
Hi again

I'll explain more. what I'm really after is how to go through a string and check it char pre char.
Example in C language you can use a silly way to check if the user typed nonalphabethical chars in his/her name.
Code:
 for(i=0;i<strlen(name);i++){
   if((char[i]<'a' ||char[i]>'z')&&(char[i]<'A' ||char[i]>'Z')){
   return falss;
 }
  return true;
 }

Yes it's true that a user can use false name and apostrophes, spaces, dashes, periods and commas and so on. This can be fixed later. What I'm really after is to kown if there is a similar mechanisme in PHP so I can learn how to use it.
So the Question is how to go through a string and check the characters one by one can compare them to ASCII?
 
PHP's grammar is based very closely on PHP's.

Taking into account that all PHP variable names must begin with "$" ( PHP strings may be referenced as character arrays ( and strlen() does the samething in PHP as it will in your code ( then this code:

Code:
for($i=0;$i<strlen($name);$i++)
{
   if(($char[i]<'a' ||$char[i]>'z')&&($char[i]<'A' ||$char[i]>'Z'))
   {
   return FALSE;
   }
  return TRUE;
}

is well-formed PHP code.


PHP also provides functionality such as regular expression engines that would allow the above to be done without the loop.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top