I am working with importing a CSV file into a MySQL database. Looking at this file in Notepad++ looks like the delimiter is a tab. Is there a way in PHP to type out the characters /t /n and /r if they exist? I tried explode() print_r() addslashes(). None seem to display what I’m looking for.
Hope the block of code below renders correctly, first time on this site.
sections after
elseif ($row == 2) {
and
} elseif (($row > 2) and ($row <= $max_row)) {
Is where I’m trying to output content to see if hidden characters are detected.
<html>
<head>
<title>AMB-Network Navigator</title>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen">
<script src="../jquery-3.2.1.min.js"></script>
</head>
<body>
<?php
/** Display PHP errors **/
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
include('index.php');
include_once('db.php');
$col_value[500000] = "";
$col_heading[500000] = "";
$sql = "";
try {
foreach ($_FILES as $key => $value) {
if (is_array($value)) {
foreach ($value as $a => $b) {
echo $a . ": " . $b . '<br>';
}
} else {
echo $key . ": " . $value . '<br>';
}
}
$size_limit = ini_get('upload_max_filesize');
echo 'upload_max_filesize = ' . $size_limit . '<br>';
$file = fopen($_FILES['file']['tmp_name'], "r");
$count_file = new SplFileObject($_FILES['file']['tmp_name'], "r");
$count_file->seek(PHP_INT_MAX);
$max_row = $count_file->key() - 1;
$row = 0;
while (($data = fgetcsv($file, 0, "\t")) !== FALSE) {
$row++;
if ($row == 1) {
$sql = "INSERT INTO report (sid, sn, modality, prod_line_desc, mpg_name, ll_name, region, country, city, customer, vos_status, return_type, recalculated_value, final_disposition, est_sales_date, est_sales_quarter, deinstall_date, opp_number, order_number, disposition_approval, est_arrival_date, installation_year, kanban_comments, sub_region, service_contract_number) ";
} elseif ($row == 2) {
echo nl2br($data[0]).$row.'<br>';
$sql .= "VALUES (`" . trim($data[0]) . "`,`" . trim($data[1]) . "`,`" . trim($data[2]) . "`,`" . trim($data[3]) . "`,`" . trim($data[4]) . "`,`" . trim($data[5]) . "`,`" . trim($data[6]) . "`,`" . trim($data[7]) . "`,`" . trim($data[8]) . "`,`" . trim($data[9]) . "`,`" . trim($data[10]) . "`,
`" . trim($data[11]) . "`,`" . trim($data[15]) . "`,`" . trim($data[21]) ."`,`" . trim($data[22]) . "`,`" . trim($data[23]) . "`,`" . trim($data[24]) . "`,`" . trim($data[25]) . "`,`" . trim($data[26]) . "`,`" . trim($data[27]) . "`,`" . trim($data[54]) . "`,`" . trim($data[56]) . "`,
`" . trim($data[77]) . "`,`" . trim($data[79]) . "`,`" . trim($data[80]) ."`,`" . trim($data[82]) . "`)";
} elseif (($row > 2) and ($row <= $max_row)) {
echo nl2br($data[0]).$row.'<br>';
$sql .= ", (`" . trim($data[0]) . "`,`" . trim($data[1]) . "`,`" . trim($data[2]) . "`,`" . trim($data[3]) . "`,`" . trim($data[4]) . "`,`" . trim($data[5]) . "`,`" . trim($data[6]) . "`,`" . trim($data[7]) . "`,`" . trim($data[8]) . "`,`" . trim($data[9]) . "`,`" . trim($data[10]) . "`,
`" . trim($data[11]) . "`,`" . trim($data[15]) . "`,`" . trim($data[21]) ."`,`" . trim($data[22]) . "`,`" . trim($data[23]) . "`,`" . trim($data[24]) . "`,`" . trim($data[25]) . "`,`" . trim($data[26]) . "`,`" . trim($data[27]) . "`,`" . trim($data[54]) . "`,`" . trim($data[56]) . "`,
`" . trim($data[77]) . "`,`" . trim($data[79]) . "`,`" . trim($data[80]) ."`,`" . trim($data[82]) . "`)";
}
}
fclose($file);
echo $sql;