Search code examples
phpcsvutf-8fgetcsv

fgetcsv not reading columns which has special characters in PHP


I am unable to get the column value which contains some special characters. I have checked many answers but i got no idea. I have pasted my sample code and data here,

$pHandle = fopen($filename, "r");
while (($data = fgetcsv($pHandle, 1600, ",")) !== FALSE) {
    echo $productName =  utf8_encode(htmlspecialchars(trim($data[0])));exit;
 }

It echo's nothing.

some sample data's

enter image description here

Any help will be much appreciated.


Solution

  • The function fgetcsv is not reading the string because the string contains an unknown character "-"(shown in the image) it's not hypen, i replaced the character by "-"hyphen and it worked.

    enter image description here