データベースからいくつかの情報をエクスポートしようとしていますが、CSV ファイルが作成されると、特殊文字は次のようになりますCategorÃa
これは、エクスポートに使用しているコードです
function exportemail() {
global $wpdb;
$content = "No.,Nombre,Empresa,Categoría,Estado de Prospecto,Correo,Teléfono,Dirección,Referido por,País,Sitio web,Contacto Alternativo,Trabajo de Contacto Alternativo,Correo de Contacto Alternativo,Teléfono de Contacto Alternativo,Dirección de Contacto Alternativo,País de Contacto Alternativo,Sitio Web de Contacto Alternativo,Notas,Rung";
if(trim($_GET['tab']) != "")
{
$sql = "SELECT * FROM ".$wpdb->prefix."crm WHERE
category LIKE '%".$wpdb->escape($_GET['tab'])."%'
ORDER BY name";
}
elseif (trim($searcharea) != '') {
$sql = "SELECT * FROM ".$wpdb->prefix."crm WHERE
name LIKE '%".$wpdb->escape($_GET['q'])."%'
OR last_name LIKE '%".$wpdb->escape($_GET['q'])."%'
OR category LIKE '%".$wpdb->escape($_GET['q'])."%'
OR business LIKE '%".$wpdb->escape($_GET['q'])."%'
OR email LIKE '%".$wpdb->escape($_GET['q'])."%'
OR phone LIKE '%".$wpdb->escape($_GET['q'])."%'
OR notes LIKE '%".$wpdb->escape($_GET['q'])."%'
OR rung LIKE '%".$wpdb->escape($_GET['q'])."%'
ORDER BY name";
} else {
$sql = "SELECT * FROM ".$wpdb->prefix."crm ORDER BY name";
}
$results = $wpdb->get_results($sql);
$c = 1;
foreach ($results as $row) {
$content .= "\n".$c.",".str_replace(","," -",
$row->name." ".
$row->last_name).",".str_replace(","," -",
$row->business).",".str_replace(","," -",
$row->category).",".str_replace(","," -",
$row->rank).",".str_replace(","," -",
$row->email).",".str_replace(","," -",
$row->phone).",".str_replace(","," -",
$row->address).",".str_replace(","," -",
$row->referral).",".str_replace(","," -",
$row->country).",".str_replace(","," -",
$row->website).",".str_replace(","," -",
$row->altern_last_name." ".
$row->altern_last_name).",".str_replace(","," -",
$row->altern_business).",".str_replace(","," -",
$row->altern_email).",".str_replace(","," -",
$row->altern_phone).",".str_replace(","," -",
$row->altern_address)." ".str_replace(","," -",
$row->altern_country).",".str_replace(","," -",
$row->altern_website).",".str_replace(","," -",
$row->notes).",".str_replace(","," -",
$row->rung);
$c++;
}
$file = "../wp-content/plugins/email.csv";
chmod($file,0777);
$fp = fopen($file,'w');
fwrite($fp,$content);
fclose($fp);
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename='.basename($file));
echo "\xEF\xBB\xBF"; // UTF-8 BOM
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
unlink($file);
exit;
}
}
この問題を解決するために htmlspecialchars を使用しようとしましたが、機能していません。問題が間違って配置されていることなのか、それとも何か他のものなのかわかりません...私は専門家ではないので、 m まだ同じです。誰かこれを手伝ってもらえますか?