/    Sign up×
Community /Pin to ProfileBookmark

How to return whois returned string to an object or array?

Hello,
I am trying to get WHOIS data through API
the API returns three values in JSO

  • 1. Result 2. Domain Availability 3. WHOIS (A string containing all the whois result)
  • How do I convert the third value string to Array or Object or something.?
    I tried exploding but sadly no luck.

    `string(4168) “{“result”:”success”,”status”:”unavailable”,”whois”:” — Domain Name: SAMPLE.COMu003Cbr /u003Ern Registry Domain ID: 5066842_DOMAIN_COM-VRSNu003Cbr /u003Ern Registrar WHOIS Server: whois.moniker.comu003Cbr /u003Ern Registrar URL: http://www.moniker.comu003Cbr /u003Ern Updated Date: 2022-03-29T18:44:00Zu003Cbr /u003Ern Creation Date: 1997-06-18T04:00:00Zu003Cbr /u003Ern Registry Expiry Date: 2023-06-17T04:00:00Zu003Cbr /u003Ern Registrar: Moniker Online Services LLCu003Cbr /u003Ern Registrar IANA ID: 228u003Cbr /u003Ern Registrar Abuse Contact Email: [email protected] /u003Ern Registrar Abuse Contact Phone: +49.68949396850u003Cbr /u003Ern Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibitedu003Cbr /u003Ern Name Server: NS1.MYTRAFFICMANAGEMENT.COMu003Cbr /u003Ern Name Server: NS2.MYTRAFFICMANAGEMENT.COMu003Cbr /u003Ern DNSSEC: unsignedu003Cbr /u003Ern URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/u003Cbr /u003Ernu0026gt;u0026gt;u0026gt; Last update of whois database: 2022-05-27T10:03:52Z u0026lt;u0026lt;u0026lt;u003Cbr /u003Ernu003Cbr /u003ErnFor more information on Whois status codes, please visit https://icann.org/eppu003Cbr /u003Ernu003Cbr /u003ErnNOTICE: The expiration date displayed in this record is the date theu003Cbr /u003Ernregistraru0027s sponsorship of the domain name registration in the registry isu003Cbr /u003Erncurrently set to expire. This date does not necessarily reflect the expirationu003Cbr /u003Erndate of the domain name registrantu0027s agreement with the sponsoringu003Cbr /u003Ernregistrar. Users may consult the sponsoring registraru0027s Whois database tou003Cbr /u003Ernview the registraru0027s reported date of expiration for this registration.u003Cbr /u003Ernu003Cbr /u003ErnTERMS OF USE: You are not authorized to access or query our Whoisu003Cbr /u003Erndatabase through the use of electronic processes that are high-volume andu003Cbr /u003Ernautomated except as reasonably necessary to register domain names oru003Cbr /u003Ernmodify existing registrations; the Data in VeriSign Global Registryu003Cbr /u003ErnServicesu0027 (u0022VeriSignu0022) Whois database is provided by VeriSign foru003Cbr /u003Erninformation purposes only, and to assist persons in obtaining informationu003Cbr /u003Ernabout or related to a domain name registration record. VeriSign does notu003Cbr /u003Ernguarantee its accuracy. By submitting a Whois query, you agree to abideu003Cbr /u003Ernby the following terms of use: You agree that you may use this Data onlyu003Cbr /u003Ernfor lawful purposes and that under no circumstances will you use this Datau003Cbr /u003Ernto: (1) allow, enable, or otherwise support the transmission of massu003Cbr /u003Ernunsolicited, commercial advertising or solicitations via e-mail, telephone,u003Cbr /u003Ernor facsimile; or (2) enable high volume, automated, electronic processesu003Cbr /u003Ernthat apply to VeriSign (or its computer systems). The compilation,u003Cbr /u003Ernrepackaging, dissemination or other use of this Data is expresslyu003Cbr /u003Ernprohibited without the prior written consent of VeriSign. You agree not tou003Cbr /u003Ernuse electronic processes that are automated and high-volume to access oru003Cbr /u003Ernquery the Whois database except as reasonably necessary to registeru003Cbr /u003Erndomain names or modify existing registrations. VeriSign reserves the rightu003Cbr /u003Ernto restrict your access to the Whois database in its sole discretion to ensureu003Cbr /u003Ernoperational stability. VeriSign may restrict or terminate your access to theu003Cbr /u003ErnWhois database for failure to abide by these terms of use. VeriSignu003Cbr /u003Ernreserves the right to modify these terms at any time.u003Cbr /u003Ernu003Cbr /u003ErnThe Registry database contains ONLY .COM, .NET, .EDU domains andu003Cbr /u003ErnRegistrars.u003Cbr /u003Ern”}”
    `

    to post a comment
    PHP

    18 Comments(s)

    Copy linkTweet thisAlerts:
    @NogDogMay 30.2022 — A quick and dirty solution(?) that may break in the future if they ever change the format of their response:
    [code=pho]
    $json = '{"result":"success","status":"unavailable","whois":" --- Domain Name: SAMPLE.COMu003Cbr /u003Ern Registry Domain ID: 5066842_DOMAIN_COM-VRSNu003Cbr /u003Ern Registrar WHOIS Server: whois.moniker.comu003Cbr /u003Ern Registrar URL: http://www.moniker.comu003Cbr /u003Ern Updated Date: 2022-03-29T18:44:00Zu003Cbr /u003Ern Creation Date: 1997-06-18T04:00:00Zu003Cbr /u003Ern Registry Expiry Date: 2023-06-17T04:00:00Zu003Cbr /u003Ern Registrar: Moniker Online Services LLCu003Cbr /u003Ern Registrar IANA ID: 228u003Cbr /u003Ern Registrar Abuse Contact Email: [email protected] /u003Ern Registrar Abuse Contact Phone: +49.68949396850u003Cbr /u003Ern Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibitedu003Cbr /u003Ern Name Server: NS1.MYTRAFFICMANAGEMENT.COMu003Cbr /u003Ern Name Server: NS2.MYTRAFFICMANAGEMENT.COMu003Cbr /u003Ern DNSSEC: unsignedu003Cbr /u003Ern URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/u003Cbr /u003Ernu0026gt;u0026gt;u0026gt; Last update of whois database: 2022-05-27T10:03:52Z u0026lt;u0026lt;u0026lt;u003Cbr /u003Ernu003Cbr /u003ErnFor more information on Whois status codes, please visit https://icann.org/eppu003Cbr /u003Ernu003Cbr /u003ErnNOTICE: The expiration date displayed in this record is the date theu003Cbr /u003Ernregistraru0027s sponsorship of the domain name registration in the registry isu003Cbr /u003Erncurrently set to expire. This date does not necessarily reflect the expirationu003Cbr /u003Erndate of the domain name registrantu0027s agreement with the sponsoringu003Cbr /u003Ernregistrar. Users may consult the sponsoring registraru0027s Whois database tou003Cbr /u003Ernview the registraru0027s reported date of expiration for this registration.u003Cbr /u003Ernu003Cbr /u003ErnTERMS OF USE: You are not authorized to access or query our Whoisu003Cbr /u003Erndatabase through the use of electronic processes that are high-volume andu003Cbr /u003Ernautomated except as reasonably necessary to register domain names oru003Cbr /u003Ernmodify existing registrations; the Data in VeriSign Global Registryu003Cbr /u003ErnServicesu0027 (u0022VeriSignu0022) Whois database is provided by VeriSign foru003Cbr /u003Erninformation purposes only, and to assist persons in obtaining informationu003Cbr /u003Ernabout or related to a domain name registration record. VeriSign does notu003Cbr /u003Ernguarantee its accuracy. By submitting a Whois query, you agree to abideu003Cbr /u003Ernby the following terms of use: You agree that you may use this Data onlyu003Cbr /u003Ernfor lawful purposes and that under no circumstances will you use this Datau003Cbr /u003Ernto: (1) allow, enable, or otherwise support the transmission of massu003Cbr /u003Ernunsolicited, commercial advertising or solicitations via e-mail, telephone,u003Cbr /u003Ernor facsimile; or (2) enable high volume, automated, electronic processesu003Cbr /u003Ernthat apply to VeriSign (or its computer systems). The compilation,u003Cbr /u003Ernrepackaging, dissemination or other use of this Data is expresslyu003Cbr /u003Ernprohibited without the prior written consent of VeriSign. You agree not tou003Cbr /u003Ernuse electronic processes that are automated and high-volume to access oru003Cbr /u003Ernquery the Whois database except as reasonably necessary to registeru003Cbr /u003Erndomain names or modify existing registrations. VeriSign reserves the rightu003Cbr /u003Ernto restrict your access to the Whois database in its sole discretion to ensureu003Cbr /u003Ernoperational stability. VeriSign may restrict or terminate your access to theu003Cbr /u003ErnWhois database for failure to abide by these terms of use. VeriSignu003Cbr /u003Ernreserves the right to modify these terms at any time.u003Cbr /u003Ernu003Cbr /u003ErnThe Registry database contains ONLY .COM, .NET, .EDU domains andu003Cbr /u003ErnRegistrars.u003Cbr /u003Ern"}';

    $json = str_replace('rn', '', $json);
    $data = json_decode($json, true);
    $response_parts = explode('<br />', $data['whois']);
    print_r($response_parts);
    [/code]
    Copy linkTweet thisAlerts:
    @slake8authorMay 30.2022 — Thank for the awesome solution

    I want to add another explode to with the semi colon but getting an HTTP ERROR 500
    ``<i>
    </i>$json = str_replace('rn', '', $json);
    $data = json_decode($json, true);
    $response_parts = explode('&lt;br /&gt;', $data['whois']);
    $semiexploded = explode(':', $response_parts[]);<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @ginerjmMay 30.2022 — I have error checking enabled and it tells me this:

    Fatal error: Cannot use [] for reading in /home/albany/public_html/homejg/test.php on line 25

    That line is

    $semiexploded = explode(':', $response_parts[]);

    And here is another message:

    Fatal error: Cannot use [] for reading in /home/albany/public_html/homejg/test.php on line 27
    Copy linkTweet thisAlerts:
    @slake8authorMay 30.2022 — Yes I have error reporting enabled and received the same error
    Copy linkTweet thisAlerts:
    @ginerjmMay 30.2022 — Well then you have your answer.
    Copy linkTweet thisAlerts:
    @slake8authorMay 30.2022 — while explode needs string as a second parameter Do I have to convert it to string first ?
    Copy linkTweet thisAlerts:
    @slake8authorMay 30.2022 — When I explode a single value it works perfectly

    $semiexploded = explode(':', $response_parts[0]);


    How to do it without the parameter to explode the whole array?
    Copy linkTweet thisAlerts:
    @NogDogMay 30.2022 — If $response_parts is an array, then you can only either refer to the entire array via that variable name (no square braces) or you can refer to one element of that array, e.g. $response_parts[1]. To do something to/with each element of an array, you would either have to loop on it (e.g. with a foreach() loop) or maybe with the array_walk() function. Maybe something like (I have too much time on my hands, today):
    [code=php]
    $json = str_replace('rn', '', $json);
    $data = json_decode($json, true);
    $response_parts = explode('<br />', $data['whois']);
    $result = array();
    foreach($response_parts as $part) {
    $parts = explode(':', $part);
    if(count($parts) >= 2) {
    $result[trim($parts[0])] = trim($parts[1]);
    }
    }
    print_r($result);
    [/code]

    But it starts to fall apart due to some of the text having semicolons, or whatever else messes it up; so again, this is not terribly reliable, and you'd be better served if you found something that gave you more of a pure JSON API to access. 🤷

    Output:
    [code=text]
    Array
    (
    [--- Domain Name] => SAMPLE.COM
    [Registry Domain ID] => 5066842_DOMAIN_COM-VRSN
    [Registrar WHOIS Server] => whois.moniker.com
    [Registrar URL] => http
    [Updated Date] => 2022-03-29T18
    [Creation Date] => 1997-06-18T04
    [Registry Expiry Date] => 2023-06-17T04
    [Registrar] => Moniker Online Services LLC
    [Registrar IANA ID] => 228
    [Registrar Abuse Contact Email] => [email protected]
    [Registrar Abuse Contact Phone] => +49.68949396850
    [Domain Status] => clientTransferProhibited https
    [Name Server] => NS2.MYTRAFFICMANAGEMENT.COM
    [DNSSEC] => unsigned
    [URL of the ICANN Whois Inaccuracy Complaint Form] => https
    [&gt;&gt;&gt; Last update of whois database] => 2022-05-27T10
    [For more information on Whois status codes, please visit https] => //icann.org/epp
    [NOTICE] => The expiration date displayed in this record is the date the
    [TERMS OF USE] => You are not authorized to access or query our Whois
    [by the following terms of use] => You agree that you may use this Data only
    [to] => (1) allow, enable, or otherwise support the transmission of mass
    )
    [/code]
    Copy linkTweet thisAlerts:
    @slake8authorMay 31.2022 — I don't know but I can't post the reply it says ( You do not have permission to do that).
    Copy linkTweet thisAlerts:
    @slake8authorMay 31.2022 — This also has some problems

    The third value Registrar URL is exploded with semicolons and does not show the full URL

    Nameservers and Domain Status show one record only not showing the full result.

    I tried getting the value from the first result before exploding them with semicolons

    Copy linkTweet thisAlerts:
    @slake8authorMay 31.2022 — I can't post the code I don't know why
    Copy linkTweet thisAlerts:
    @slake8authorMay 31.2022 — ``<i>
    </i>$json = str_replace('rn', '', $json);
    $data = json_decode($json, true);
    $response_parts = explode('&lt;br /&gt;', $data['whois']);<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @slake8authorMay 31.2022 — ``<i>
    </i>$NS1 = $response_parts[''12'];
    $NS2 = $response_parts[''13'];<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @slake8authorMay 31.2022 — ``<i>
    </i>$NS1_ Result = ''subst'r'(''$NS1', ''16');
    $NS2_ Result ='' substr'(''$NS2', ''16');<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @slake8authorMay 31.2022 — ``<i>
    </i>echo $...NS1_Result ."&lt;br&gt;";
    echo $...NS2_Result ."&lt;br&gt;";<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @slake8authorMay 31.2022 — Results

    GLORIA.NS.CLOUDFLARE.COM

    KONNOR.NS.CLOUDFLARE.COM

    but the problem is that it is not the same result every time, Sometimes nameservers are four instead of two then the array number will be changed.

    I apologize I posted to code in parts

    I don't know why I was unable to post the code direct

    Copy linkTweet thisAlerts:
    @slake8authorMay 31.2022 — I found this solution

    ``<i>
    </i>$json = str_replace('rn', '', $json);
    $data = json_decode($json, true);
    $newexplode = explode("&lt;br /&gt;", $data['whois']);
    $newarray=[];
    foreach ($newexplode as $key =&gt; $val) {
    $explode = explode(":", $val);
    $eplo0 = $explode[0];
    $explode[0] = "";
    $remaining = implode(":", $explode);
    $newarray[$eplo0][]=$remaining;
    }
    echo "&lt;pre&gt;";
    print_r($newarray);<i>
    </i>
    ``
    Copy linkTweet thisAlerts:
    @NogDogMay 31.2022 — Unfortunately, this forum has some annoying security checks that block things it thinks might be code injection attacks. Two of those things are opening &lt;-?-php tags (which I obfuscated here with hyphens) and HTML script tags. You need to similarly obfuscate them or just omit them if it's all PHP (or JavaScript) code.

    Maybe some day the sight owners will fix that, but it's been months now, so don't hold your breath. :(
    ×

    Success!

    Help @slake8 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...