tags:

views:

45

answers:

2

This is the function:

function NewsDat($url="http://www.url.com/dat/news.dat", $max=5){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $curlresult = curl_exec($ch);

    $posts = explode("\n", $curlresult); //chop it up by carriage return
    unset($curlresult);

    $num=0; 
    $result=array();
    foreach($posts as $post){
        $result[] = explode("::", $post);
        $num++;
        if($num>$max-1){
            break;
        }
    }
    return $result; 
}

var_dump(NewsDat());

Which returns:

array(5) { [0]=>  array(14) { [0]=>  string(10) "1183443434" [1]=>  string(1) "R" [2]=>  string(46) "Here is some text"...

I need to echo: 1183443434 and Here is some text...

Can anyone help?

+1  A: 

Basic array handling?

$result = NewsDat();
echo $result[0][0]; //holds "1183443434"
echo $result[0][2]; //holds "Here is some text"

But I don't know if the values are always at this positions when you run your function.

Felix Kling
+1  A: 

Well as NewsDat return an array of arrays, if you need this two fields on each lines, this should do the trick:

$news = NewsDat();

foreach($news as $single_new)
{
    echo $single_new[0] . " - " . $single_new[2] . "\n";
}

If you only need these two fields, just:

$news = NewsDat();
$field1 = $news[0][0];
$field2 = $news[0][2];
echo $field1 . " - " . $field2 . "\n";
Patrick MARIE