Crazy Horse
asked on
Export to csv removes leading zero of mobile number
When exporting a mobile number to csv, it is leaving off the first 0. I have tried various methods I found online to overcome this but none of them worked except one, well so I thought. It was to do this:
On a Mac using Numbers this works perfectly. But some windows users have said that they can see "=""0551236373"" instead of just 0551236373 in the csv.
I also tried this but still no 0 is shown.
Any ideas?
fputcsv($file, array('="'.$mobile_no.'"') );
On a Mac using Numbers this works perfectly. But some windows users have said that they can see "=""0551236373"" instead of just 0551236373 in the csv.
I also tried this but still no 0 is shown.
$mobile_test = sprintf('%01s', $mobile_no);
Any ideas?
How are the users opening/viewing the file?
ASKER
They are opening it with Notepad++
I suspect this is a formatting issue. When you export data to CSV, it gets exported as expected. However, most people then open CSV files in a spreadsheet program such as Excel. Excel see a phone number as 'numeric' rather than 'text', and therefore drops the leading digit. It on'y gets dropped from the display - the data is still there - if you select the column and explicitly format it as text/string, you'll get the leading zero back again.
ASKER
Thanks Chris, the issue is that this export needs to be uploaded to a third party. So, do you think once uploaded it will have the zero there even though it can't be seen when viewing the file in excel, numbers etc.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice one!