PDA

View Full Version : Character in string



Maikovich
March 31st, 2010, 06:47 PM
Can you check whether there's a character in a string?

Like:

$str = "haha@hotmail.com";

Can you check with php if theres a @ sign and a dot sign in the string??

Zugzwang
March 31st, 2010, 06:50 PM
Sure you can.

Have a look at the documentation of PHP, section "String Functions": http://www.php.net/manual/en/ref.strings.php - The function "strpos" looks promising in this context.

hessiess
March 31st, 2010, 07:12 PM
You can use a regular expression for that.

http://www.totallyphp.co.uk/code/validate_an_email_address_using_regular_expression s.htm

Bachstelze
March 31st, 2010, 07:22 PM
You can use a regular expression for that.

http://www.totallyphp.co.uk/code/validate_an_email_address_using_regular_expression s.htm

You can, but it's a bad idea. strpos() is the right way to do this.

Hellkeepa
March 31st, 2010, 09:22 PM
HELLo!

That depends upon what the OP wants to do, if he wants to validate an e-mail address then RegExps are the way to go. If he just wants to check for the occourance of a character in a string, "strpos ()" is the way to go.

Happy codin'!