Home > Article > Backend Development > PHP function to verify whether the URL is legal_PHP tutorial
There are two types of URL verification. One is to use regular expressions to verify whether the URL conforms to the URL rules, and the other is to use functions to verify whether the URL is legal. Visit the specified URL to see if it can be accessed normally. If it can be accessed normally, it is a legal URL address.
Example 1
The code is as follows | |||||
function isValidUrl($url) {
|
Example 2
The above example only verifies whether the URL is normal and does not mean whether it can be accessed. We can use the curl function to perform the method
The code is as follows | |||||
$url = "http://www.45it.net ";
|
In addition to this function, you can also use many functions of PHP such as file, file_get_contents(), and fopen functions for detection.