Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For this project: <a href="http://drupal.org/project/parallel" rel="nofollow noreferrer">http://drupal.org/project/parallel</a></p> <p>Usage:</p> <pre><code>echo parallel_get_domain("www.robknight.org.uk") . "&lt;br&gt;"; echo parallel_get_domain("www.google.com") . "&lt;br&gt;"; echo parallel_get_domain("www.yahoo.com") . "&lt;br&gt;"; </code></pre> <p>Functions:</p> <pre><code>/** * Given host name returns top domain. * * @param $host * String containing the host name: www.example.com * * @return string * top domain: example.com */ function parallel_get_domain($host) { if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' &amp;&amp; strnatcmp(phpversion(),'5.3.0') &lt; 0) { // This works 1/2 the time... CNAME doesn't work with nslookup for ($end_pieces = substr_count($host, '.'); $end_pieces &gt; 0; $end_pieces--) { $test_domain = end(explode('.', $host, $end_pieces)); if (checkdnsrr($test_domain)) { $domain = $test_domain; break; } } return isset($domain) ? $domain : FALSE; } else { // This always works $sections = explode('.', $host); array_unshift($sections, ''); foreach($sections as $key =&gt; $value) { $parts[$key] = $value; $test_domain = implode('.', parallel_array_xor($parts, $sections)); if (checkdnsrr($test_domain, 'NS') &amp;&amp; !checkdnsrr($test_domain, 'CNAME')) { $domain = $test_domain; break; } } return isset($domain) ? $domain : FALSE; } } /** * Opposite of array_intersect(). * * @param $array_a * First array * @param $array_b * Second array * * @return array */ function parallel_array_xor ($array_a, $array_b) { $union_array = array_merge($array_a, $array_b); $intersect_array = array_intersect($array_a, $array_b); return array_diff($union_array, $intersect_array); } /** * Win compatible version of checkdnsrr. * * checkdnsrr() support for Windows by HM2K &lt;php [spat] hm2k.org&gt; * http://us2.php.net/manual/en/function.checkdnsrr.php#88301 * * @param $host * String containing host name * @param $type * String containing the DNS record type * * @return bool */ function parallel_win_checkdnsrr($host, $type='MX') { if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { return FALSE; } if (empty($host)) { return FALSE; } $types=array('A', 'MX', 'NS', 'SOA', 'PTR', 'CNAME', 'AAAA', 'A6', 'SRV', 'NAPTR', 'TXT', 'ANY'); if (!in_array($type, $types)) { user_error("checkdnsrr() Type '$type' not supported", E_USER_WARNING); return FALSE; } @exec('nslookup -type=' . $type . ' ' . escapeshellcmd($host), $output); foreach($output as $line){ if (preg_match('/^' . $host . '/', $line)) { return TRUE; } } } // Define checkdnsrr() if it doesn't exist if (!function_exists('checkdnsrr')) { function checkdnsrr($host, $type='MX') { return parallel_win_checkdnsrr($host, $type); } } </code></pre> <p>Output - Windows:</p> <pre><code>org.uk google.com yahoo.com </code></pre> <p>Output - Linux:</p> <pre><code>robknight.org.uk google.com yahoo.com </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload