| | |
Filter url to domain
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
In these three functions, you can filter to a url to just the domain name. There are three main methods of doing so which are all shown in the example and the usage of each function is shown in the example.
<?php //function one - get entire domain function fulldomain($domainb) { $bits = explode('/', $domainb); if ($bits[0]=='http:' || $bits[0]=='https:') { return $bits[0].'//'.$bits[2].'/'; } else { return 'http://'.$bits[0].'/'; } unset($bits); } //function two - use regex to get entire domain function preg_fulldomain ($domainb) { return preg_replace('/^((http(s)?:\/\/)?([^\/]+)(\/)?)(.*)/','$1',$domain b); } //function three - get domain and remove subdomain. function domain($domainb) { $bits = explode('/', $domainb); if ($bits[0]=='http:' || $bits[0]=='https:') { $domainb= $bits[2]; } else { $domainb= $bits[0]; } unset($bits); $bits = explode('.', $domainb); $idz=count($bits); $idz-=3; if (strlen($bits[($idz+2)])==2) { $url=$bits[$idz].'.'.$bits[($idz+1)].'.'.$bits[($idz+2)]; } else if (strlen($bits[($idz+2)])==0) { $url=$bits[($idz)].'.'.$bits[($idz+1)]; } else { $url=$bits[($idz+1)].'.'.$bits[($idz+2)]; } return $url; } //below is the usage of each function $address='http://www.subdomain.example.com/blog/index.php?id=1'; echo fulldomain($address); echo '<br>'; echo preg_fulldomain($address); echo '<br>'; echo domain($address); ?>
Similar Threads
- php search engine problems (PHP)
- Domain Names & Websites for sale (Websites for Sale)
- problem with select statement filter thru GET url... (PHP)
- fetching Unique URL, Domain name and sub domain names from Web Page (Python)
- code to hide the url using servlet filter (JSP)
- BookRead.com - Domain Name & Functioning Site (Websites for Sale)
- Domain Name Divert (Site Layout and Usability)
- WebServer (Networking Hardware Configuration)
| Thread Tools | Search this Thread |
Tag cloud for domain, filter, function, url
301 apps array background binary bitmap bmp branding broken business c# c++ calling case class clean compression content control convert country cpanel cron cybersquatting datagrid decimals decode desktop dns domain download drawing duplicate dynamic economy encode file filter free function gay gdi+ generator google hosting htaccess html i/o icann image incode inline internet investment job lamp laptop link list login mail math media mediawiki method mod_rewrite news numbers parameter php plotting pointer python random recursion recursive redirect reference registration return rss sales stream string studio textbox tree ubuntu uk url urllib2 variable vb.net void web zone




