質問
ファイルを変数に読み込んで Word 文書内の文字列を置換しようとしています $content
次に、str_ireplace() を使用して文字列を変更します。ファイルから内容を読み取ることはできますが、str_ireplace() で文字列を置換できないようです。PHP ドキュメントによれば、文字列は「バイナリ セーフ」であるため、そうなると思いました。申し訳ありませんが、私は PHP ファイル操作の初心者なので、これはすべて私にとってまったく新しいことです。
これは私が書いたものです。
copy('jack.doc' , 'newFile.doc');
$handle = fopen('newFile.doc','rb');
$content = '';
while (!feof($handle))
{
$content .= fread($handle, 1);
}
fclose($handle);
$handle = fopen('newFile.doc','wb');
$content = str_ireplace('USING_ICT_BOX', 'YOUR ICT CONTENT', $content);
fwrite($handle, $content);
fclose($handle);
新しいファイルをダウンロードすると、MS Word で正常に開きますが、置換すべき文字列ではなく、古い文字列が表示されます。
この問題を解決できますか?PHP 経由で MS Word の文字列を置換するために使用できる、より良いツールはありますか?
解決 4
私は教師が来年営業責任者を取得しようとしています。平均時にそれらを;
他のヒント
PHPを使用して .doc または .docx ファイルと同じ要件を持っています。
そして私はそれに投稿を書いています。org / update-docx-file-uniting-php /
.copy('jack.doc' , 'newFile.doc');
$full_path = 'newFile.doc';
if($zip_val->open($full_path) == true)
{
// In the Open XML Wordprocessing format content is stored.
// In the document.xml file located in the word directory.
$key_file_name = 'word/document.xml';
$message = $zip_val->getFromName($key_file_name);
$timestamp = date('d-M-Y H:i:s');
// this data Replace the placeholders with actual values
$message = str_replace("client_full_name", "onlinecode org", $message);
$message = str_replace("client_email_address", "ingo@onlinecode.org", $message);
$message = str_replace("date_today", $timestamp, $message);
$message = str_replace("client_website", "www.onlinecode.org", $message);
$message = str_replace("client_mobile_number", "+1999999999", $message);
//Replace the content with the new content created above.
$zip_val->addFromString($key_file_name, $message);
$zip_val->close();
}
これは正しい方向を向いています。 http://davidwalsh.name/read-pdf-doc-file-php
私がこれまでに見つけた解決策(テストされていません):
docvert - Doc、Free、しかし直接使用できない
phpwordlib - Docのための作品、無料ではありません。
phpdocx - DOCXのみ、Zend。
Webサービスに到達できる場合は、
Linux上でWord文書ファイルを処理する方法はたくさんあります
antiword
- プレーンテキストに変換されるため、あまり効果的ではありません。pyODconvert
open-office
またはliboffice
- UNOを通じてunoconv
ユーティリティ - サーバーへのインストール許可が必要です
オンラインでのファイル変換に最も適した Python スクリプトが 1 つありますが、これらのファイルはコマンド ラインで変換する必要があります。
PHP コードのみを使用して Word ファイルを処理する具体的かつ満足のいく解決策はありません。
私はこの提案にたどり着くまでに長い間探しました。