[nycphp-talk] How to read MS Word document using PHP as like text file?
Dan Cech
dcech at phpwerx.net
Mon Nov 20 07:38:50 EST 2006
Janaksinh Jadeja wrote:
> Hi
>
> I wish to read MS Word document content using PHP as like text file. Is
> anybody know any open source PHP script for it. or any other way to do it?
One easy way to grab the text from a word doc is to use the command line
program catdoc.
here are a couple of examples to get you started.
Dan
function catdoc_string($str)
{
// requires catdoc
// write to temp file
$tmpfname = tempnam ('/tmp','doc');
$handle = fopen($tmpfname,'w');
fwrite($handle,$a);
fclose($handle);
// run catdoc
$ret = shell_exec('catdoc -ab '.escapeshellarg($tmpfname) .' 2>&1');
// remove temp file
unlink($tmpfname);
if (preg_match('/^sh: line 1: catdoc/i',$ret)) {
return false;
}
return trim($ret);
}
function catdoc_file($fname)
{
// requires catdoc
// run catdoc
$ret = shell_exec('catdoc -ab '.escapeshellarg($fname) .' 2>&1');
if (preg_match('/^sh: line 1: catdoc/i',$ret)) {
return false;
}
return trim($ret);
}
More information about the talk
mailing list