Hi Dave
Thank you very much for your help. As far as I know "foreach" isn't supported by PHP3 aswell. Therefore I tryed to change these lines to work with PHP 3. After a few parsing errors I finally got some more errors, such as:
Warning: Variable passed to reset() is not an array or object in /www/aare-web/php/tab.php3 on line 59
Warning: Variable passed to current() is not an array or object in /www/aare-web/php/tab.php3 on line 63
Warning: Variable passed to next() is not an array or object in /www/aare-web/php/tab.php3 on line 65
Warning: Variable passed to current() is not an array or object in /www/aare-web/php/tab.php3 on line 70
Warning: Variable passed to next() is not an array or object in /www/aare-web/php/tab.php3 on line 72
Something must be wrong with my arrays but I can't figur out what :-((
This is the script which should read data out of a textfile (delimited with 😉 and put it in a simple table with rows and cols, depending on the amount of data...
<?php
function array_merge2($array1, $array2) {
for($i=0;$i<count($array1);$i++){
$str=$array1[$i]; {
$str.="$key => $value,\n";
if (isset($keys[$key]) && !is_string($key)) {
$keys[]=$value;
} else {
$keys[$key]=$value;
}
}
}
}
for($i=0;$i<count($array2);$i++){
$str=$array2[$i]; {
$str.="$key => $value,\n";
if (isset($keys[$key]) && !is_string($key)) {
$keys[]=$value;
} else {
$keys[$key]=$value;
}
}
return $keys;
}
function array_shift2($arr) {
$start=true;
unset($new_arr);
for($i=0;$i<count($arr);$i++){
$str=$arr1[$i];
$str.="$key => $value,\n";
if ($start) {
$to_ret=$value;
$start=false;
} else {
$new_arr[$key]=$value;
}
}
$arr=$new_arr;
return $to_ret;
}
function my_fgetcsv($filename,$sep) {
$arr=file($filename);
$erg=array("");
for($i=0;$i<count($arr);$i++){
$str=$arr[$i];
$buf=explode ($sep,$str);
$erg=array_merge2($erg,$buf);
}
array_shift2($erg);
return $erg;
}
function table_out($rows,$cols,$arr,$width,$border,$cp,$cs,$color) {
reset ($arr); //line 59
$cellwd=100/$cols."%";
echo "<table width='$width' border='$border' cellpadding='$cp' cellspacing='$cs'>";
for ($c=0;$c<$cols;$c++) {
$elem=pos($arr); //line62
echo "<th width='$cellwd' bgcolor='$color'>$elem</th>";
next($arr); //line65
}
for ($r=1;$r<$rows;$r++) {
echo "<tr>";
for ($c=0;$c<$cols;$c++) {
$elem=pos($arr); //line70
echo "<td bgcolor='$color'>$elem</td>";
next($arr); //line72
}
echo "</tr>";
}
echo "</table>";
}
$arr=my_fgetcsv("Kurse.txt",";");
table_out(5,5,$arr,"90%",0,2,2,"#E8E8E8");
?>
What's wrong now???
Thanks for any help!!
Kind Regards from Switzerland.
Brigitte