PDA

Click to See Complete Forum and Search --> : Parsing Data


eiSecure
Jun 3rd, 2002, 08:13 PM
Let's say I have data that's something like this:

title:author:title2:autor2:title3:author3

How would I seperate it to have a database table populated with the authors in one column and its corresponding title in another?:confused:

The Hobo
Jun 3rd, 2002, 09:50 PM
$stuff = "title:author:title2:autor2:title3:author3";
$info = explode(":", $stuff);
$count = count($info);

for ($i = 0; $i < $count; $i++) {
if (even($info[$i] == 1) {
echo $info[$i];
} else {
echo " - " . $info[$i] . "<br>\n";
}
}


function even($var) {
return ($var % 2 == 0);
}


This is how I'd do it. Although I ran that off the top of my head, it should work.