How to Check If String is URL or Not in PHP?
Hey Developer,
Now, let's see post of how to check string is url or not in php. This post will give you a simple example of how to check if string is url in php. if you want to see an example of check if string is url php then you are in the right place. you can understand a concept of check value is url or not.
In PHP, you can check if a string is a valid URL or not by using the filter_var() function with the FILTER_VALIDATE_URL filter. Here's an example code snippet:
Example:
<?php
$url = "https://www.example.com";
if (filter_var($url, FILTER_VALIDATE_URL) !== false) {
echo "$url is a valid URL";
} else {
echo "$url is not a valid URL";
}
In this example, the filter_var() function checks if the $url variable is a valid URL using the FILTER_VALIDATE_URL filter. If the URL is valid, it will return the URL string, otherwise it will return false.
You can also use regular expressions to check if a string matches the format of a URL, but using the filter_var() function is a more reliable and convenient method.
I hope it can help you...

Hardik Savani
I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP - jquery datatables with mysql database example from scratch
- PHP - How to custom file uploading with CKEDITOR?
- PHP - Getting Started PHPUnit test with simple example
- PHP - Bootstrap autocomplete tokenfield with Ajax Example
- PHP - import excel file into mysql database tutorial
- PHP - Capture screenshot of website from URL example
- PHP - How to remove duplicate values from multidimensional array?
- How to get current year rows using MySql Query PHP?
- How to get filename without extension in PHP?
- How to Remove Specific Element by Value from Array in PHP?
- How to Get Minimum Key Value of Array in PHP?
- How to access PHP variables in JQuery?
- How to Get Product using Rakuten Marketing API in PHP?
- How to Remove Null Values from Array in PHP?