I've seen many questions but wasn't able to understand how it works as I want a more simple case.
If we have text, whatever it is, I'd like to check if it is a URL or not.
$text = "something.com"; //this is a url
if (!IsUrl($text)){
echo "No it is not url";
exit; // die well
}else{
echo "Yes it is url";
// my else codes goes
}
function IsUrl($url){
// ???
}
Is there any other way rather than checking with JavaScript in the case JS is blocked?
To find details of specific URLs with technical duplicates, click on the blue URL Details button from the URL List. The URL Details tab will slide across, and you then need to navigate to Duplicate Content -> URLs, and you'll see all the duplicate URLs underneath.
HTMLInputElement. checkValidity() method is used to check if a string in <input> element's value attribute is URL . The checkvalidity() method returns true if the value is a proper URL and false if the input is not a proper URL.
This question already has answers here: $text = "something.com"; //this is a url if (! IsUrl($text)){ echo "No it is not url"; exit; // die well }else{ echo "Yes it is url"; // my else codes goes } function IsUrl($url){ // ??? }
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With