Search code examples
ms-wordfile-get-contentsfile-formatfile-conversionreadfile

How to read files which contain gap i filenames using 'antiword'?


I am using 'antiword' to convert MSword document to text. I have a file with name "care job house keeper catering job13806.doc" and antiword cannot read this if passed in script.

  public function Convert($filenames) {         
    return $content = shell_exec('antiword'." ".$filenames.' -');//dash at the end to output content        
}

If a manually enter filename by typing antiword and pressing tab after few charters of filename it looks as below and executes perfectly.

$ antiword care\ job\ housekeeper\ catering\ job13806.doc

Solution

  • Use quotes:

    shell_exec("antiword '$filename' -");
    

    That'd produce:

    antiword 'care job housekeeper catering job13806.doc' -