0

So I have a text file with sets of 4 items I want to go in different arrays. I've tried the following but without success.

<?php
$urls="list.txt";
$page = join("",file("$urls"));
$kw = explode("|", $page);
$count = 0;
$links = array();
$images = array();
$widths = array();
$heights = array();
for($i=0;$i<count($kw);$i++){
    $count++;

    if ($count==1){
        $links[$i] = array($kw[$i]);
    }

    if ($count==2){
        $images[$i] = array($kw[$i]);
    }

    if ($count==3){
        $widths[$i] = array($kw[$i]);
    }

    if ($count==4){
        $heights[$i] = array($kw[$i]);
        $count = 0;
    }

}

?>

I'm not sure where my logic is wrong, but when I print the arrays out I dont get anything.
Thanks in advance.

3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by Bachu
0

edit: forgot to give an example of what is in the file;

imgur.com | link.gif | 40 | 80 | google.com | ebay.jpg | 42 | 129 |

1

Try this

<?php
$urls="list.txt";
$page = join("",file("$urls"));
$kw = explode("|", $page);
$count=0;
$arrayRow=0;
$links = array();
$images = array();
$widths = array();
$heights = array();

foreach($kw as $key=>$vl) {
    $count++;
    if ($count==1)    $links[$arrayRow] = $vl;

    if ($count==2)     $images[$arrayRow] = $vl;

    if ($count==3)     $widths[$arrayRow] = $vl;

    if ($count==4){
        $heights[$arrayRow] = $vl;
        $count = 0;
        $arrayRow++;
    }
}

?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.