Created
November 20, 2012 10:13
-
-
Save EspadaV8/4117116 to your computer and use it in GitHub Desktop.
iOS6 SQLite to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT [0], | |
h.id, | |
m.date + 978307020000, | |
CASE m.is_from_me | |
WHEN 0 THEN 1 | |
WHEN 1 THEN 2 | |
END AS type, | |
NULL, | |
m.text, | |
NULL, | |
NULL, | |
m.service_center, | |
1, | |
-1 | |
FROM message m, | |
handle h | |
WHERE h.rowid = m.handle_id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$count = 0; | |
$messages = ""; | |
if (($handle = fopen('sms.csv', 'r')) !== false) { | |
while(($data = fgetcsv($handle)) !== false) { | |
$count++; | |
$messages .= '<sms protocol="' . $data[0] . '" ' . | |
'address="' . $data[1] . '" '. | |
'date="' . $data[2] . '" '. | |
'type="' . $data[3] . '" '. | |
'subject="null" ' . // $data[4] . '" '. | |
'body="' . $data[5] . '" '. | |
'toa="null" ' . // $data[6] . '" '. | |
'sc_toa="null" ' . // $data[7] . '" '. | |
'service_center="' . $data[8] . '" '. | |
'read="' . $data[9] . '" '. | |
'status="' . $data[10] . '" '. | |
' />' . PHP_EOL; | |
} | |
} | |
$output = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>" . PHP_EOL; | |
$output .= '<smses count="' . $count . '">' . PHP_EOL; | |
$output .= $messages; | |
$output .= "</smses>" . PHP_EOL; | |
file_put_contents('sms.xml', $output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment