嗨,我有一个文本文件,我在php中读取并将其拆分为数组。 之后,我有很多数组,其中有些是空的。如何删除这些emty数组以及如何将数据导入mysql数据库?连接就在那里。
//$DatabaseHost = "localhost";
//$DatabaseUser = "xx";
//$DatabasePassword = "xxx";
//$Database = "xxxx";
//$Table = "xxxx";
//******** Datenbank Connect ********
//$DatabaseConnect = mysql_connect($DatabaseHost, $DatabaseUser, $DatabasePassword) or die ("Keine Verbindung zum Server");
//$DatabaseSelect = mysql_select_db($Database, $DatabaseConnect) or die ("Die Datenbank gibt es nicht");
$datei = file("daten/neuer0.txt");
foreach($datei AS $ausgabe)
{ $zerlegen = explode(",", $ausgabe); }
function multiexplode ($delimiters,$string) {
$ready = str_replace($delimiters, $delimiters[0], $string);
$launch = explode($delimiters[0], $ready);
return $launch;
}
$text = $ausgabe;
{
$exploded = multiexplode(array(",",".","|",":","\"","\\",),$text);
print_r($exploded);
答案 0 :(得分:0)
例如,可以使用array_filter和array_unique函数避免空白值,
$array = array("1" => "PHP code tester Sandbox Online",
"foo" => "bar", 5 , 5 => 89009,
"case" => "Random Stuff: " . rand(100,999),
"PHP Version" => phpversion(),"bb"=>''
);
$get_final_dga_data=array_unique($array);
$get_final_dga_data=array_filter($get_final_dga_data);
print_r($get_final_dga_data);