Skip to content

Instantly share code, notes, and snippets.

View N30's full-sized avatar

Neo N30

View GitHub Profile
@egulhan
egulhan / check-if-contain-domain-name.php
Last active January 22, 2023 01:33
Validate domain name or check if a string contains a domain name using PHP
<?php
/**
* Checks if string contains a domain name
* @param $string
* @return false|int
*/
function checkIfContainsDomainName($string)
{
$pattern = '/(http[s]?\:\/\/)?(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}/';