Checking Text Contain Domain/URL or Not

Sometimes programmers/developers need to check text contains the domain/URL or not. Here is the code snippet for checking domain/URL contain or not in the text.


 * This function will check the text and find the domain name from test.
 * If any domain found then it will validate domain name. If domain valid
 * then return true otherwise return false.
 * @param $textString
 * @return bool
function isDomainContain($textString)
    $pattern = '/(http[s]?\:\/\/)?(?!\-)(?:[a-zA-Z\d\-]{0,62}[a-zA-Z\d]\.){1,126}(?!\d+)[a-zA-Z\d]{1,63}/';
    preg_match($pattern, $textString, $domains);
    foreach ($domains as $domain){
        if (filter_var($domain, FILTER_VALIDATE_URL) || checkdnsrr($domain)) {
            return true;

    return false;

$textString = 'Stack Overflow is a question and answer site for professional and enthusiast programmers. 
It is a privately held website, the flagship site of the Stack Exchange Network, created in 2008 by Jeff 
Atwood and Joel Spolsky. It features questions and answers on a wide range of topics in computer programming.';

    echo 'Domain found';
} else {
    echo 'Domain not found';

Parsing XML With Multiple Namespaces Using PHP

Yesterday, I had a very ugly XML data which had to parse. It has multiple namespaces and namespaces are irrelevant with DOM – I just wasn’t getting the nodeValue from the Element. It was parsing partially not all nodeValues due to namespaces are irrelevant with DOM. Then I applied little tricks onto it through XML children options. And I thought I need to share this code so other developers can save his time to get out this annoying issue.