Welcome Guest, Not a member yet? Register   Sign In
Finding URL & Email text in a string?
#2

[eluser]dejan[/eluser]
Do you need to extract an email and/or URL from a string, or check if a string is valid email/url?

If latter, it's easy:

filter_var($string, FILTER_VALIDATE_EMAIL);
filter_var($string, FILTER_VALIDATE_URL);

If former, it's a bit trickier. You can either try with regex, which I suggest you google for, or you can tokenize the string and check each token, like so:

foreach (preg_split('/\b/', $string) as $token) {
if (filter_var($token, FILTER_VALIDATE_EMAIL)) return $token;
}

\b in regex is word boundry (space, comma, dot, semicolon, etc.).


Messages In This Thread
Finding URL & Email text in a string? - by El Forum - 08-16-2012, 06:34 AM
Finding URL & Email text in a string? - by El Forum - 08-16-2012, 07:54 AM
Finding URL & Email text in a string? - by El Forum - 08-16-2012, 09:08 AM
Finding URL & Email text in a string? - by El Forum - 08-17-2012, 03:28 PM
Finding URL & Email text in a string? - by El Forum - 08-17-2012, 11:08 PM
Finding URL & Email text in a string? - by El Forum - 08-17-2012, 11:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB