9
validatewebsite
validate_website
SYNOPSIS
validate_website($url)
DESCRIPTION
validate_website returns true if $url is a valid website address.
A website address may optionally begin with http://, https:// and www..
EXAMPLE
php > require 'library/validatewebsite.php';
php > var_dump(validate_website('www.izend.org'));
bool(true)
php > var_dump(validate_website('https://www.izend.org'));
bool(true)
php > var_dump(validate_website('izend.org'));
bool(true)
php > var_dump(validate_website('izend'));
bool(false)
CODE
- function validate_website($url) {
- return preg_match('#^(http(s)?://)?(www\.)?(([^\.]+)\.)+[a-z]{2,}$#', $url);
- }
normalize_website
SYNOPSIS
normalize_website($url)
DESCRIPTION
CODE
- function normalize_website($url) {
- return preg_replace('#^(http(s)?://)?((www\.)?([^\.]+)\.[a-z]{2,})$#', '\3', $url);
- }
Comments