0

I got a ouput from whois search result as punch of content i want to make bold text or add any other HTML element before the ': ' Sentence and also after ': '

bunch of content eg.

devims.com domain lookup results from whois.PublicDomainRegistry.com server: Domain Name: DEVIMS.COM Registry Domain ID: 1615408964_DOMAIN_COM-VRSN Registrar WHOIS Server: whois.publicdomainregistry.com Registrar URL: www.publicdomainregistry.com Updated Date: 2012-05-30T12:18:42Z Creation Date: 2010-09-12T14:54:29Z Registrar Registration Expiration Date: 2016-09-12T14:54:29Z Registrar: PDR Ltd. d/b/a PublicDomainRegistry.com Registrar IANA ID: 303 Registrar Abuse Contact Email: abuse-contact@publicdomainregistry.com Registrar Abuse Contact Phone: +1-2013775952 Domain Status: clientTransferProhibited (http://icann.org/epp#clientTransferProhibited) Registry Registrant ID: Registrant Name: devi sri mari Registrant Organization: devIMS Registrant Street: No.53, First Street, S.S Nagar, Thirumullaivoiyal, Registrant City: Chennai Registrant State/Province: Tamil Nadu Registrant Postal Code: 600062 Registrant Country: IN Registrant Phone: +044.42839080 Registrant Phone Ext: Registrant Fax: Registrant Fax Ext: Registrant Email: devi@devims.com Registry Admin ID: Admin Name: devi sri mari Admin Organization: devIMS Admin Street: No.53, First Street, S.S Nagar, Thirumullaivoiyal, Admin City: Chennai Admin State/Province: Tamil Nadu Admin Postal Code: 600062 Admin Country: IN Admin Phone: +044.42839080 Admin Phone Ext: Admin Fax: Admin Fax Ext: Admin Email: devi@devims.com Registry Tech ID: Tech Name: devi sri mari Tech Organization: devIMS Tech Street: No.53, First Street, S.S Nagar, Thirumullaivoiyal, Tech City: Chennai Tech State/Province: Tamil Nadu Tech Postal Code: 600062 Tech Country: IN Tech Phone: +044.42839080 Tech Phone Ext: Tech Fax: Tech Fax Ext: Tech Email: devi@devims.com Name Server: ns743.hostgator.com Name Server: ns744.hostgator.com DNSSEC:Unsigned URL of the ICANN WHOIS Data Problem Reporting System: http://wdprs.internic.net/ >>>Last update of WHOIS database: 2015-02-11T04:42:33+0000Z<<< For more information on Whois status codes, please visit https://icann.org/epp Registration Service Provided By: HOSTMACRO WEB SERVICES The data in this whois database is provided to you for information purposes only, that is, to assist you in obtaining information about or related to a domain name registration record. We make this information available "as is", and do not guarantee its accuracy. By submitting a whois query, you agree that you will use this data only for lawful purposes and that, under no circumstances will you use this data to: (1) enable high volume, automated, electronic processes that stress or load this whois database system providing you this information; or (2) allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via direct mail, electronic mail, or by telephone. The compilation, repackaging, dissemination or other use of this data is expressly prohibited without prior written consent from us. The Registrar of record is PDR Ltd. d/b/a PublicDomainRegistry.com. We reserve the right to modify these terms at any time. By submitting this query, you agree to abide by these terms

expected ouput in html

eg. <li>Registrar WHOIS Server</li>:
<li>whois.publicdomainregistry.com </li>

or 

eg. <b>Registrar WHOIS Server</b>: 
<li>whois.publicdomainregistry.com </li>


eg. <li>Registrar WHOIS Server</li>:
<li>whois.publicdomainregistry.com </li>

or 

eg. <b>Registrar WHOIS Server:</b> 
<li>whois.publicdomainregistry.com </li>

What i tried: My Code

  $result = "Registrar WHOIS Server: whois.publicdomainregistry.com Registrar URL: www.publicdomainregistry.com Updated Date: 2012-05-30T12:18:42Z Creation Date: 2010-09-12T14:54:29Z Registrar Registration Expiration Date: 2016-09-12T14:54:29Z Registrar: PDR Ltd. d/b/a PublicDomainRegistry.com Registrar IANA ID: 303 Registrar Abuse Contact Email: abuse-contact@publicdomainregistry.com Registrar Abuse Contact Phone: +1-2013775952 Domain Status: clientTransferProhibited (http://icann.org/epp#clientTransferProhibited) Registry Registrant ID: Registrant Name: devi sri mari Registrant Organization: devIMS Registrant Street: No.53, First Street, S.S Nagar, Thirumullaivoiyal, Registrant City: Chennai Registrant State/Province: Tamil Nadu Registrant Postal Code: 600062 Registrant Country: IN Registrant Phone: +044.42839080 Registrant Phone Ext: Registrant Fax: Registrant Fax Ext: Registrant Email: devi@devims.com";
        echo $result;
        $res = explode( ': ', $result );
        foreach ($res as $value) {
            echo '<li>'. $value .'</li>';
    }

        print_r( explode( ': ', $result ) );

Output

  Array
    (
        [0] => Registrar WHOIS Server
        [1] => whois.publicdomainregistry.com Registrar URL
        [2] => www.publicdomainregistry.com Updated Date
        [3] => 2012-05-30T12:18:42Z Creation Date
        [4] => 2010-09-12T14:54:29Z Registrar Registration Expiration Date
        [5] => 2016-09-12T14:54:29Z Registrar
        [6] => PDR Ltd. d/b/a PublicDomainRegistry.com Registrar IANA ID
        [7] => 303 Registrar Abuse Contact Email
        [8] => abuse-contact@publicdomainregistry.com Registrar Abuse Contact Phone
        [9] => +1-2013775952 Domain Status
        [10] => clientTransferProhibited (http://icann.org/epp#clientTransferProhibited) Registry Registrant ID
        [11] => Registrant Name
        [12] => devi sri mari Registrant Organization
        [13] => devIMS Registrant Street
        [14] => No.53, First Street, S.S Nagar, Thirumullaivoiyal, Registrant City
        [15] => Chennai Registrant State/Province
        [16] => Tamil Nadu Registrant Postal Code
        [17] => 600062 Registrant Country
        [18] => IN Registrant Phone
        [19] => +044.42839080 Registrant Phone Ext
        [20] => Registrant Fax
        [21] => Registrant Fax Ext
        [22] => Registrant Email
        [23] => devi@devims.com
    )

expected output

 Array
    (
        [0] => Registrar WHOIS Server
        [1] => whois.publicdomainregistry.com 
        [2] => Registrar URL  
        [3] => www.publicdomainregistry.com
        [4] => Updated Date
        [5] => 2012-05-30T12:18:42Z
        [6] => reation Date
        [7] => 2010-09-12T14:54:29Z
        [8] => Registrar Registration Expiration Date
        [9] => 2016-09-12T14:54:29Z
        [10] => Registrar URL
        [11] => PDR Ltd. d/b/a PublicDomainRegistry.com
        [12] => Registrar IANA ID
        ....
    )
Kundan SIngh
  • 720
  • 2
  • 12
  • 34

1 Answers1

2

I would say that the real problem here is that you have removed the newlines from the whois output. Had you kept the newlines, you should have been able to better separate the keys from the values. Now there is no good way of telling what is part of a value and what is part of the next key, which is why the resulting output have them mixed up.

So, try to get hold of the whois output without the newlines stripped off. Then you can do this:

// Note: Newlines added to $result below (and string shortened a bit)
$result = "Registrar WHOIS Server: whois.publicdomainregistry.com\nRegistrar URL: www.publicdomainregistry.com\nUpdated Date: 2012-05-30T12:18:42Z\nCreation Date: 2010-09-12T14:54:29Z\nRegistrar Registration Expiration Date: 2016-09-12T14:54:29Z\nRegistrar: PDR Ltd. d/b/a PublicDomainRegistry.com";

$out = array();
$rows = explode("\n", $result);
foreach ($rows as $row) {
    preg_match('/(.*?)\: (.*)/', $row, $matches);
    $out[] = $matches[1]; // Key
    $out[] = $matches[2]; // Value
}
print_r($out);

Output:

Array
(
    [0] => Registrar WHOIS Server
    [1] => whois.publicdomainregistry.com
    [2] => Registrar URL
    [3] => www.publicdomainregistry.com
    [4] => Updated Date
    [5] => 2012-05-30T12:18:42Z
    [6] => Creation Date
    [7] => 2010-09-12T14:54:29Z
    [8] => Registrar Registration Expiration Date
    [9] => 2016-09-12T14:54:29Z
    [10] => Registrar
    [11] => PDR Ltd. d/b/a PublicDomainRegistry.com
)

If you really are stuck with the whois output without newlines, you will have to know all keys you are interested in and make the separation between keys and values based on that, rather than just the colons:

$result = "Registrar WHOIS Server: whois.publicdomainregistry.com Registrar URL: www.publicdomainregistry.com Updated Date: 2012-05-30T12:18:42Z Creation Date: 2010-09-12T14:54:29Z Registrar Registration Expiration Date: 2016-09-12T14:54:29Z Registrar: PDR Ltd. d/b/a PublicDomainRegistry.com Registrar IANA ID: 303 Registrar Abuse Contact Email: abuse-contact@publicdomainregistry.com Registrar Abuse Contact Phone: +1-2013775952 Domain Status: clientTransferProhibited (http://icann.org/epp#clientTransferProhibited) Registry Registrant ID: Registrant Name: devi sri mari Registrant Organization: devIMS Registrant Street: No.53, First Street, S.S Nagar, Thirumullaivoiyal, Registrant City: Chennai Registrant State/Province: Tamil Nadu Registrant Postal Code: 600062 Registrant Country: IN Registrant Phone: +044.42839080 Registrant Phone Ext: Registrant Fax: Registrant Fax Ext: Registrant Email: devi@devims.com";

$keys = array("Registrar WHOIS Server", "Registrar URL", "Registrar WHOIS Server", "Registrar URL", "Updated Date", "Creation Date", "Registrar Registration Expiration Date", "Registrar", "Registrar IANA ID", "Registrar Abuse Contact Phone", "Domain Status", "Registry Registrant ID", "Registrant Name", "Registrant Organization", "Registrant City", "Registrant State\/Province", "Registrant Postal Code", "Registrant Country", "Registrant Phone", "Registrant Fax", "Registrant Fax Ext", "Registrant Email");
$keysImploded = implode('|', $keys);
$out = array();

while (preg_match('/(' . $keysImploded . '): (.*)/', $result, $matches)) {
    $out[]  = $matches[1];
    $result = $matches[2];

    preg_match('/(.*?)((' . $keysImploded . ': |$).*)/', $result, $matches);
    $out[]  = $matches[1];
    $result = $matches[2];
}
print_r($out);

Output:

Array
(
    [0] => Registrar WHOIS Server
    [1] => whois.publicdomainregistry.com
    [2] => Registrar URL
    [3] => www.publicdomainregistry.com
    [4] => Updated Date
    [5] => 2012-05-30T12:18:42Z
    [6] => Creation Date
    [7] => 2010-09-12T14:54:29Z
    [8] => Registrar Registration Expiration Date
    [9] => 2016-09-12T14:54:29Z
    [10] => Registrar
    [11] => PDR Ltd. d/b/a PublicDomainRegistry.com
    ....
)

This approach, however, requires that you know beforehand what (possible) keys there are in the whois result string and that those key names followed by a colon and a space (e.g. "Registrar: ") does not occur anywhere in the value strings.

mhall
  • 3,671
  • 3
  • 23
  • 35
  • whois result comes without newlines, that is the main issue and i have strucked due to that and also confused with tiring of many logics – Kundan SIngh Feb 11 '15 at 10:40