0

I am trying to cut results out of the RBL data it pulls back.

Here is the code.

<?
$ips = file("list.inc");
foreach($ips as $ip)
{
$rblurl = 'http://rbl-check.org/rbl_api.php?ipaddress=' . trim($ip);
$boom = fopen($rblurl, "r");
$rbl = stream_get_contents($boom);
echo "</br>";
$data = explode(";",$rbl);
print "<pre>";
print_r($data[0]);
print "</pre>";
echo "</br>";
//fclose($boom);
}
?>

This is the result.

emailbasura;bl.emailbasura.org;nowebsite;notlisted
Sorbs;zombie.dnsbl.sorbs.net;nowebsite;notlisted
msrbl;combined.rbl.msrbl.net;nowebsite;notlisted
nixspam;ix.dnsbl.manitu.net;nowebsite;notlisted
Spamcop;bl.spamcop.net;nowebsite;notlisted

I am trying to cut the first part and the last part so it only displays this.

emailbasura notlisted
Sorbs notlisted
msrbl notlisted
nixspam notlisted
Spamcop notlisted

Any help would be great!

3
  • Maybe preg_grep() help to you? Commented Feb 22, 2013 at 22:45
  • 1
    Or read it as CSV with semicolons being the delimiter, see str_getcsv(). You forgot to break up the lines beforehand, btw. Commented Feb 22, 2013 at 22:47
  • How can the result contain ; when you just have exploded on ;? I would expect the result to be just emailbasura. And you need to do it line-by-line of course. Commented Feb 22, 2013 at 22:49

3 Answers 3

1

first you need to explode the data by the line breaks not just the delimeter:

$data = explode("\n",$rbl);

once you've done that you just echo out the data:

foreach($data as $item) {
  $item = explode(';',$item);
  echo $item[0].' '.$item[3];
}
Sign up to request clarification or add additional context in comments.

Comments

0
foreach($data as $d) 
{
  $arr_data = explode(';',$d);
  $first_data = $arr_data[0];
  $last_data =  $arr_data[3];
}

Comments

0

Change here

print "<pre>";
print_r($data[0]);
print "</pre>"

as

print "<pre>";
$spl = split(';', $data[0]);
echo $spl[0] . $spl[3];
print "<pre>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.