operations on MS word file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

operations on MS word file

Post by itsmani1 »

Can I perform operatrions on MS word file using php? If I can than is there a special way to do so?

For example there is file abc.doc

It contains a line " Hello [[field1]],"
Now i want to find and replace this [[field1]] by "Mike"

How can i do this?


Output will be:

Hello Mike,


Thank you
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Have a search of PHPClasses.org. I am sure there are file exporting and importing classes that you could use there.
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

What if i try to convert word file to an html file?
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

I am trying this code to edit word file, it works fine if the both strings are same lenght but not if both are of different length.
any help

Code: Select all

<?PHP
	$tmp=	file_get_contents("work.doc");
	$tmp = str_replace ("sys" , "asd",$tmp);
	$tmp=	file_put_contents("work2.doc" , $tmp);
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Word files are binary, you cannot simply str_replace() things in them.
Xoligy
Forum Commoner
Posts: 53
Joined: Sun Mar 04, 2007 5:35 am

Post by Xoligy »

Why not use mail merge?
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

what is mail merge?
Post Reply