User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 392,076 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,034 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2333 | Replies: 2
Reply
Join Date: Aug 2006
Posts: 7
Reputation: bluephoenix66 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bluephoenix66 bluephoenix66 is offline Offline
Newbie Poster

Question How to fill a word template with php??

  #1  
Sep 6th, 2006
I have an e-commerce website and I am trying to have a webpage create a .doc or .rtf document to print labels based on the customers' addresses in a mysql database.

For this reason, I need to create a document based on a labels template.

I have saved the labels template as whslabels.rtf on the website, and on every label I have written "Address1", "Address2", "Address3", ... then I have the mentioned webpage do a str_replace replacing the "Address..." words with the customer's address, and then save this to a new file named "newlabels6.rtf".


[php]
[code]
$template_file = "whslabels.rtf";
$handle = fopen($template_file , "r");
$contents = fread($handle, filesize($template_file));

$original= array("Address1", "Address2");
$new = array("pizza", "beer");

$newphrase = str_replace($original, $new, $contents);

$handle2 = fopen("newlabel6.rtf" , "w");

fwrite ( $handle2 ,$newcontents);
fclose ($handle);
fclose($handle2);
[code]
[php]


but when I go to open the new .rtf file it doesn't seem to able to open it. The exact error I get is "The document file or path is not valid...."


What am I doing wrong?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation: Puckdropper is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 20
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: How to fill a word template with php??

  #2  
Sep 7th, 2006
Are you writing plain text to a rich text file? That may not be the source of your problem, but it could be the source of another problem later.

I'd double check my paths and capitolzation, my quick look at your code segment didn't pick up anything immediately wrong.

One more thing, you only need to use either [ code ] or [ php ] tags, not both. The reason it failed to display properly is because you didn't turn them off (using [ /code ] or [ /php ]). BBCode like this takes a bit to get used to.
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote  
Join Date: Aug 2006
Posts: 7
Reputation: bluephoenix66 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bluephoenix66 bluephoenix66 is offline Offline
Newbie Poster

Re: How to fill a word template with php??

  #3  
Sep 7th, 2006
$template_file = "whslabels.rtf";
$handle = fopen($template_file , "r");
$contents = fread($handle, filesize($template_file));
 
$original= array("Address1", "Address2");
$new = array("Here is address one", "Here is address 2");
 
$newphrase = str_replace($original, $new, $contents);
 
$handle2 = fopen("newlabel6.rtf" , "w");
 
fwrite ( $handle2 ,$newcontents);
fclose ($handle);
fclose($handle2);

Basically the template is a typical sheet of 21 labels made with Word, and originally saved as a .dot file. The addresses are made up in HTML by the php page, but instead of displaying the on the screen is trying to subsitute address 1 with lets say:

[html]
Mr John Smith<BR>
Flat 12, 42 Piccdilly Circus<BR>
W1<BR>
London<BR>
UK
[/html]

I have never done this before, and that is the only thing I could think of to reach my objective: having a page of lables ready to print with the address of the day's customers' orders.

The .dot file has originally Address1, Address2, Address3, ... where the addresses will go.


but when I go to open the new .rtf file it doesn't seem to able to open it. The exact error I get is "The document file or path is not valid...."


What am I doing wrong?[/quote]
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 12:14 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC