php readwrite docx

<?php
//Add YGuang 20130508


include_once('tbszip.php');


$zip = new clsTbsZip();


// Open the document
// $inFileName = "Text.docx";
$inFileName = "temp1.docx";
$outFileName = "New.docx";
$inPattern = "/AAA/"; /*<? ?>  ^<$ */ 
$outStr = "BBB";
$zip->Open($inFileName);
$content = $zip->FileRead('word/document.xml');
$p = strpos($content, '</w:body>');
if ($p===false) exit("Tag </w:body> not found in document.");


$content = preg_replace($inPattern,$outStr,$content);


//
echo $content;
// Add the text at the end
// $content = substr_replace($content, '<w:p><w:r><w:t> </w:t></w:r></w:p>', $p, 0);
$zip->FileReplace('word/document.xml', $content, TBSZIP_STRING);


// Save as a new file
$zip->Flush(TBSZIP_FILE, $outFileName);




?>

你可能感兴趣的:(php readwrite docx)