Validate url
Let's see how to validate a url.
Use the filter_Var() built-in function.
And use the constant FILTER_VALIDATE_URL as argument.
How to validate URLs using filter_Var()
filter_Var('URL',FILTER_VALIDATE_URL);
The first argument uses the URL address, the second uses the constant FILTER_VALIDATE_URL.
As shown in the example, you can change the purpose according to the value of a constant.
Returns true if the URL address is valid or false.
Here is an example of URL validation:
<?php $url = "COREASURDOMAIN"; $checkUrl = filter_Var($url, FILTER_VALIDATE_URL); if($checkUrl == true) { echo "correct URL"; } else { echo "not correct URL"; } ?>
Result
이번에는 틀린 URL 주소를 입력해서 테스트 해봅시다.
<?php $url = "www.coreasur.com"; $checkUrl = filter_Var($url, FILTER_VALIDATE_URL); if($checkUrl == true) { echo "correct URL"; } else { echo "not correct URL"; } ?>
result