I'm struggling with the following.
After a user uploads a CSV file, I want to compare that header of the CSV file match content and order.
I have tried with several PHP methods, I always have a FALSE result on the first value on my string.
So I basically make a string of control an array with explode()
and then get the first line of my CSV.
CSV file
value1,value2,value3
My First Value,My Second Value,My Third Value
Code
$controlHeader = explode(',',"value1,value2,value3");
$csvHeader = fgetcsv($file_handle, 2000, ',');
foreach($csvHeader as $key => $header){
if (strpos($controlHeader[$key],$header) === false){
echo('false');
} else {
echo 'true';
}
}
Is there any reason why my First value in CSV line is always considered as different than the control one?
I also try with array_diff()
it always reports the key [0]
as different.
Of course, My CSV header is good, trust me I've triple check that.
WHat I'm missing here?