How to get a domain and it’s TLD from a URL string using PHP and Regular Expression: preg_match(“/[a-z0-9\-]{1,63}\.[a-z\.]{2,6}$/”, parse_url($_url_string, PHP_URL_HOST), $_domain_tld); echo $_domain_tld[0]; This is particularly useful for dealing with country TLD’s, like co.uk, on.gc along with the general .com, .net, etc. It is also capable of ruling-out multiple subdomains like: http://i83tr.cdn-2.delivery.net/homepage/sprite.png so you end… Continue reading How to Get The Domain and TLD from a URL using PHP and Regular Expression
Tag: RegExp
Replace HTML tags with PHP
preg_replace(‘@< (iframe|script|noscript)\b.*?>.*?@si’, ”, $string); Removes iframe, script and noscript tags and contents from $string. Performs an inverted version of strip_tags function.