PHP code example of badcow / dns-parser

1. Go to this page and download the library: Download badcow/dns-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

badcow / dns-parser example snippets


$file = file_get_contents('/path/to/example.com.txt');

$zone = Badcow\DNS\Parser\Parser::parse('example.com.', $file);



 = file_get_contents('/path/to/example.com.txt');
$zone = Badcow\DNS\Parser\Parser::parse('example.com.', $file);

$zone->getName(); //Returns example.com.
foreach ($zone->getResourceRecords() as $record) {
    $record->getName();
    $record->getClass();
    $record->getTtl();
    $record->getRdata()->output();
}

$spf = function (\ArrayIterator $iterator): Badcow\DNS\Rdata\TXT {
    $string = '';
    while ($iterator->valid()) {
        $string .= $iterator->current() . ' ';
        $iterator->next();
    }
    $string = trim($string, ' "'); //Remove whitespace and quotes

    $spf = new Badcow\DNS\Rdata\TXT;
    $spf->setText($string);

    return $spf;
};

$customHandlers = ['SPF' => $spf];

$record = 'example.com. 7200 IN SPF "v=spf1 a mx ip4:69.64.153.131