I have a CSV file with a list of station names. Some of the names contain right single quotation mark: ’ (not a normal single quote).
I am trying to read it from the file and insert into the database. All the stations work fine, but ones with the quote get inserted into the database as 0
.
I was trying to replace it to a normal quote mark, but PHP doesn't seem to find the quote in the string.
if(strpos($stationName, "’") !== false){
var_dump($stationName);
var_dump(str_replace("’", "'", $stationName));
die();
}
The code above never gets triggered. Do I need to do something with the encoding within PHP or MySQL and how should I go about fixing this?
Example of string that works fine: Langton Matravers, Crack Lane Bottom (N-bound)
And example that gets inserted as 0
: Harman’s Cross, Wilkswood Farm Road (NW-bound)
I am using Laravel if that makes any difference.
Thank you.
EDIT:
I've run detect decoding, which showed me that the string is in ASCII
encoding - I believe this could be the issue, but I can't seem to change the encoding?
I run the following lines:
$stationName = mb_convert_encoding($stationName, "UTF-8", "ASCII");
var_dump(mb_detect_encoding($stationName));
And still get the output that the string is in ASCII
?
EDIT2:
Turns out that this was issue with the actual CSV file encoding and the way the CSV library I was using (Laravel-Excel) was reading it. Adjusting the config and converting the CSV file encodings seems to have fixed the issue.
Turns out that this was issue with the actual CSV file encoding and the way the CSV library I was using was reading it. Adjusting the config and converting the CSV file encoding to UTF-8
seems to have fixed the issue.