PHP interesse |
|
Hallo allen,
Ik moet voor een kennis een zeer oude windows mailserver converten naar een linux postfix server, echter staan zijn forwards in mysql.
Nu kan ik uiteraard dit uitlezen, echter staan er bij de forwards ook nog $user in.
b.v.
login: jantje@domein
forward: $user,jantje@domein2
Hoe haal ik die "$user," weg ? (en nee niet in elke output staat dit)
Het script hiervoor is :
<?php
$host="*****"; // Host name
$username="*****"; // Mysql username
$password="*****"; // Mysql password
$db_name="*****"; // Database name
$tbl_name="*****"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$domeinfile= fopen("/tmp/forwardsfromsql","w");
$listresult=mysql_query("SELECT login,forward FROM $tbl_name WHERE forward != ''");
$countresult=mysql_num_rows($listresult);
if ($countresult < 1) {
print("No domeinnaam found in the database.<br>");
} else {
while($rowdomain=mysql_fetch_array($listresult)) {
$login=$rowdomain[login];
$forward=$rowdomain[forward];
fputs($domeinfile, "$login $forward\n");
}
}
fclose($domeinfile);
mysql_close();
?>
<?php $host="*****"; // Host name $username="*****"; // Mysql username $password="*****"; // Mysql password $db_name="*****"; // Database name $tbl_name="*****"; // Table name // Connect to server and select database. $domeinfile= fopen("/tmp/forwardsfromsql","w"); $listresult=mysql_query("SELECT login,forward FROM $tbl_name WHERE forward != ''"); if ($countresult < 1) { print("No domeinnaam found in the database.<br>"); } else { $login=$rowdomain[login]; $forward=$rowdomain[forward]; fputs($domeinfile, "$login $forward\n"); } } ?>
Alvast bedankt
-- edit --
momenteel heb ik :
$domeinfile= fopen("/tmp/forwardsfromsql2","w");
$listresult=mysql_query("SELECT login,forward FROM $tbl_name WHERE forward != ''");
$countresult=mysql_num_rows($listresult);
if ($countresult < 1) {
print("No domeinnaam found in the database.<br>");
} else {
while($rowdomain=mysql_fetch_array($listresult)) {
$login=$rowdomain[login];
$forward=$rowdomain[forward];
$array = explode(",", $forward);
//print_r($array);
$forward = '';
while (list($key, $val) = each($array)) {
if($val == "\$user") {
} else {
$forward .= "".$val.",";
}
}
fputs($domeinfile, "$login $forward\n");
}
}
fclose($domeinfile);
mysql_close();
$domeinfile= fopen("/tmp/forwardsfromsql2","w"); $listresult=mysql_query("SELECT login,forward FROM $tbl_name WHERE forward != ''"); if ($countresult < 1) { print("No domeinnaam found in the database.<br>"); } else { $login=$rowdomain[login]; $forward=$rowdomain[forward]; //print_r($array); $forward = ''; while (list($key, $val) = each($array)) { if($val == "\$user") { } else { $forward .= "".$val.","; } } fputs($domeinfile, "$login $forward\n"); } }
echter op het einde zit ik nog met een ,
Die moet ik nog welslopen
|