check if a string is a URL
PHP's filter_var
function is what you need. Look for FILTER_VALIDATE_URL
. You can also set flags
to fine-tune your implementation.
No regex needed....
The code below worked for me:
if(filter_var($text, FILTER_VALIDATE_URL))
{
echo "Yes it is url";
exit; // die well
}
else
{
echo "No it is not url";
// my else codes goes
}
You can also specify RFC compliance and other requirements on the URL using flags. See PHP Validate Filters for more details.