Is it possible to somehow use PHP to read the contents of a .pst file?
There's a standalone program to convert PST to other formats (which may be then readable using PHP extensions, e.g. php_imap): http://www.five-ten-sg.com/libpst/
However, as Microsoft keeps changing the PST format, it's not guaranteed that you'll be able to convert all PST files.
Exporting folders from MS Outlook (FILE -> OPEN -> IMPORT -> EXPORT TO A FILE) into plain text CSV enables easy parsing e.g. via fgetcsv function. The libpst is only supported on linux (RPM).
Format of PST file is complex and parsing it with PHP would be a tremendous job.
Related
Im trying to fix a CSV using PHP.
The file is also very large 500mb. I need to convert it from utf-16le to UTF-8. Issue is I used fgets() initially and found out it doesnt work with utf-16le.
How can I convert this file to UTF-8 without using fgets? The file is too big to load to memory.
I have already searched the forum and there are a lot of ways to convert the encoding but not for a file this big that uses utf-16le.
The solution here is to leave this task to the operating system by the means of exec, shell_exec or bactick operator.
I used:
shell_exec ( 'iconv -f utf-16le -t utf-8 1.csv > 2.csv' );
DO NOT USE FGETS FOR utf-16le!!!!!!! It will destroy the formatting of the file.
I use Excel Writer of Harish Chauhan to generate an excel (xls) file.
Then I use phpExcelReader 2 to read the file created by the Excel Writer class but have this error all the time :
The filename myXls.xls is not readable
I can open the "myXls.xls" file with MS Excel. But if I save the file with another name , it can be read successfully.
Try to explore the code, it seems that the error was given by :
if (substr($this->data, 0, 8) != IDENTIFIER_OLE) {
//echo 'Error';
$this->error = 1;
return false;
}
IDENTIFIER_OLE was defined :
define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1));
I dont have any idea about how to fix it. Please help.
Thanks for your time!
The file generated by Harish Chauhan's ExcelWriter class is not an actual OLE BIFF .xls file, but a mix of HTML markup and some elements from SpreadSheetML, the XML format defined by Microsoft as an alternative to BIFF in Excel 2003. It never proved particularly popular; but the later versions of MS Excel itself can still read and write this format. MS Excel is also very forgiving about reading HTML markup, though the latest version will give you a notice informing you if a file format does not match its extension.
phpExcelReader 2 is written to read Excel BIFF files, therefore it is incapable of reading the non-OLE/non-BIFF files generated by Harish Chauhan's class.
If you want to write and read files in the correct format, then I suggest you use PHPExcel, or one of the many other PHP libraries that work with genuine Excel files.
I had the same problem. The task was to parse very old XLS file (Excel2). I could not find any library in PHP which works with such an old format.
So the solution was to make conversion with LibreOffice command line to XLSX (works to CSV also) and then parse it with any "moderner" Excel parser.
We got LibreOffice installed in our server and this is the command to convert:
libreoffice --headless --convert-to xlsx original_source.xls
or
libreoffice --headless --convert-to csv original_source.xls
the best way to solve this was to use "pdftotext" that is in the "xpdf" package but in all shared hosts that i googled shell_exec is disabled . i found alternative metods that used only php like a function called pdf2string() (on php.net) but none of those functions didn't work as expected (with some pdf files they just didn't output correct text and with some other pdf they didn't output nothing and some other versions of this function just didnt work at all so i excluded this option). any way to convert that open source pdftotext into a php script ? (source is in c++ i think and can be found here : http://www.foolabs.com/xpdf/download.html) . any other solution will be accepted as far as it gives to me text output of the pdf (the correct one)
Since you have a restricted environment, you may want to look at this.
http://webcheatsheet.com/php/reading_clean_text_from_pdf.php
This uses no external library to parse pdf to text formats.
However, since this parse text out of raw pdf format, i m not sure how stable it is.
I have got a huge xml file (~ 85 Mo) and I would like to open it with XML Reader (then my script read selected lines). I have downloaded it on my PC and my script works (using Wamp).
Now I would like to do the same online. Server login is aaa and password is bbb (of course it's an example).
I tried the following statement:
$xml = new XMLReader();
if ($xml->open('ftp://aaa:bbb#ftp.website.com/myfile.xml')){
echo 'OK';
}
while($xml->read()){
// my script here...
}
It seems I am wrong because my web browser indicates me that the page is too long to load. What is the good way to proceed? Or did I miss something important?
Since the file in question is an XML it is not wise to partially download it since it will probably break the xml structure making the parser to fail.
You could get a cronjob to retrieve the file occasionally and you would open it from a local location on the server, or retrieve it once and cache it locally so that it would speed subsequent requests.
http://davidwalsh.name/increase-php-script-execution-time-limit-ini_set
The default execution time is 20 secs or 30, increase it to 1 minute and retry
I would use curl to connect to the FTP server and download the file.
http://php.net/manual/en/book.curl.php
Your probably best to download the file to the server first using PHP's FTP functions and then open the file locally. I wouldn't rely on using FTP within the XML library, you'll get more flexibility this way.
Consider this:
$text = "hello";
$text_compressed = gzcompress($text, 6);
$success = file_put_contents('file.gz', $text_compressed);
When i try to open file.gz, i get errors. How can i open file.gz under terminal without calling php? (using gzuncompress works just fine!)
I can't recode every file i did, since that i now have almost a Billion files encoded this way! So if there is a solution... :)
You need to use gzencode() instead.
Luckily for you, the fix is easy: just write a script that opens each of your files one by one, uses gzuncompress() to uncompress that file, and then writes that file back out with gzencode() instead of gzcompress(), repeating the process for all of the files.
Alternatively (since you said you "didn't want to recode your files"), you could use uncompress to open the existing files from the command line (instead of gunzip/zcat).
As noted on the gzcompress() manual page:
gzcompress
This is not the same as gzip compression, which includes some header data. See gzencode() for gzip compression.
As said, you don't really have gzipped files. To open your files from a terminal you need the uncompress utility.