<? // create a reference to a new COM component (Word) $word = new COM("word.application") or die("Can't start Word!"); // print the version of Word that's now in use //$word->Documents->Open("test.doc"); // set the visibility of the application to 0 (false) // to open the application in the forefront, use 1 (true) $word->Visible = 0; // create a new document in Word $word->Documents->Add(); // add text to the new document $word->Selection->TypeText("Testing 1-2-3..."); //save the document in the Windows temp directory $word->Documents[1]->SaveAs("D:/comtest.doc"); // close the connection to the COM component $word->Quit(); // print another message to the screen echo "Check for the file..."; ?>
$a = "test.doc";
$d = fopen($a,"r");
$c = fread($d,filesize($a));
$b = str_replace("quit","good",$c);
fclose($d);
$f = fopen($a,"w+");
$e = fwrite($f,$b);
fclose($f);
?>
win下载编码是unicode,是双字节字符
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>Untitled Document</title>
</head><body>
<?php
$strFileData = readfromfile("test.doc");
echo base64_encode("quit")."<br>";
echo base64_encode("good")."<br>";
$strFileData = str_replace(base64_encode("quit"), base64_encode("good"), $strFileData);
echo $strFileData."<br>";
if(writetofile ("QDD1.doc", $strFileData))
echo "ok";
?>
</body>
</html><?
function readfromfile($file_name)
{ //File Reading
if (file_exists($file_name))
{
//if (Php_VERSION >= "4.3.0") return file_get_contents($file_name);
$filenum=fopen($file_name,"r");
$sizeofit=filesize($file_name);
if ($sizeofit<=0)
return "";
@flock($filenum,LOCK_EX);
$file_data=base64_encode(fread($filenum, $sizeofit));
fclose($filenum);
return $file_data;
}
else
return "Not Read";
} function writetofile ($filename, $data)
{ //File Writing
$filenum=@fopen($filename,"w");
if (!$filenum)
{
return false;
}
flock($filenum,LOCK_EX);
$file_data=fwrite($filenum,base64_decode($data));
fclose($filenum);
return true;
}
?>
// create a reference to a new COM component (Word)
$word = new COM("word.application") or die("Can't start Word!"); // print the version of Word that's now in use
//$word->Documents->Open("test.doc");
// set the visibility of the application to 0 (false)
// to open the application in the forefront, use 1 (true)
$word->Visible = 0; // create a new document in Word
$word->Documents->Add(); // add text to the new document
$word->Selection->TypeText("Testing 1-2-3..."); //save the document in the Windows temp directory
$word->Documents[1]->SaveAs("D:/comtest.doc"); // close the connection to the COM component
$word->Quit(); // print another message to the screen
echo "Check for the file..."; ?>
你可以用VB或者其他软件查看一下word.application的参数和函数等。根据函数写吧。不过。。各个版本的application好象都不一样的。以前写过一段,但现在全忘了