PDA

View Full Version : STR_REPLACE to .doc?



Todd W
10-07-2007, 10:38 PM
Anyone know of a function that I can open up a doc and perform a str_replace on?

I have some %first_name% type stuff in a .DOC I need to replace with the data from my database and I've never dealt with .doc files before.

And yest hey have to be .DOC.

They could technically be .PDF too but I'd have to then convert the .Doc file to PDF, and also figure a way to replace the data.

Thanks
-Todd

mobilebadboy
10-08-2007, 03:28 PM
Just make sure the file is writeable.


$file = file_get_contents("filename.doc");
$replace = str_replace("%first_name%","Joe",$file);
$fp = fopen("filename.doc", "w");
fwrite($fp, $replace);
fclose($fp);

Todd W
10-08-2007, 04:53 PM
Just make sure the file is writeable.


$file = file_get_contents("filename.doc");
$replace = str_replace("%first_name%","Joe",$file);
$fp = fopen("filename.doc", "w");
fwrite($fp, $replace);
fclose($fp);

.doc files don't work like that

mobilebadboy
10-08-2007, 09:00 PM
I tried it and it worked. Must be in a different format.

Chris
10-09-2007, 05:50 AM
They do, sorta. Doc files will have the raw text in them, atleast they did last time I forced one to open in a text editor. It was surrounded by a ton of garbage and formatting code, but the text was still there.

Todd W
10-09-2007, 09:51 AM
Well I convinced them to go with PDF so now I need to find a PDF class to open/edit/close/save a PDF file.

Thanks guys.
-Todd

Westech
10-09-2007, 10:19 AM
http://us2.php.net/manual/en/ref.pdf.php

Todd W
10-09-2007, 10:49 AM
Thanks!

Todd W
10-24-2007, 05:41 PM
http://us2.php.net/manual/en/ref.pdf.php

Ok, so they want almost $200 for that library :flare: know of a better way?

-Todd

rpanella
10-24-2007, 07:30 PM
I've never used it, but might want to check out http://www.fpdf.org/
________
TOYOTA WIKI HISTORY (http://www.toyota-wiki.com/wiki/Toyota_Wiki)

Todd W
10-24-2007, 10:46 PM
I've never used it, but might want to check out http://www.fpdf.org/

Yup, I used that.

Then I ended up just converting the .DOC to .HTML in WORD and wow that made it all easier ;) Now the end user does not even need extra software to print the paper, faster processing time, and I can create them on the fly quicker too.

-Todd