Link to home
Start Free TrialLog in
Avatar of Crazy Horse
Crazy HorseFlag for South Africa

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:

fputcsv($file, array('="'.$mobile_no.'"') );

Open in new window


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);

Open in new window


Any ideas?
Avatar of Norie
Norie

How are the users opening/viewing the file?
Avatar of Crazy Horse

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.
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
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nice one!