PDA

View Full Version : [PHP] Checking if value contains @



thesleuth
September 2nd, 2006, 05:59 AM
Is there a script where it will check if the link value contains a @. if it does, it will add mailto: infront of the link value. Also, if it does not have @ but has www., the script will add http:// infront of the link value.

What kind of function do I use?
Thanks in advance.

bwh2
September 2nd, 2006, 09:27 AM
you will use regex.

good resource: http://weblogtoolscollection.com/regex/regex.php

icio
September 2nd, 2006, 01:15 PM
There is a PHP function called `strpos`. It returns the position of a string within another string and false if the string is not found.

$input = "paul@asdf.com";
if (strpos($input, "@")!==false) {
// String contains a '@'
} else if (strpos($input,"www.")==0) {
// String starts with 'www.'
}

hl
September 2nd, 2006, 01:32 PM
I'd recommend the regex method though.