Wednesday, 15 April 2015

Check if a string contains nothing but an URL in PHP -



Check if a string contains nothing but an URL in PHP -

i wondering if proper way check, if string contains nil url:

if (stripos($string, 'http') == 0 && !preg_match('/\s/',$string)) { do_something(); }

stripos() checks if string starts "http" preg_match() checks if string contains spaces

if not so, assume string nil url - assumption valid? there improve ways accomplish this?

use filter_var()

if (filter_var($string, filter_validate_url)) { // you're }

the filters can more refined. see manual more on this.

php url validation

No comments:

Post a Comment