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
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Sat Sep 08, 2007 11:02 pm
I'm using something close to this for creating a document.
Code: Select all
$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);
How can I open that document and append to it? I'm having trouble it think its just over writing the file.
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Sat Sep 08, 2007 11:08 pm
a+ i know... its not working heres what i have....
Code: Select all
$numberoftests = $_POST['numberoftests'];
//chmod("/home/cmmvideo/public_html/eTests/QuickTests/documents/","777");
$documentname = md5(time());
//echo $documentname;
for($counter = 1; $counter <= $numberoftests; $counter += 1){
if(!file_exists("documents/".$documentname.".doc")){
$new_doc = fopen("documents/".$documentname.".doc" , "w");
} else {
$new_doc = fopen("documents/".$documentname.".doc" , "a+");
}
if($counter > 1){
$newtests = generate_more_tests($line);
$newtestquestions = $newtests[0];
$newtestanswers = $newtests[1];
$d_q_output = $newtestquestions;
$d_a_output = $newtestanswers;
} else {
$d_q_output = $q_output;
//print_r($d_q_output);
$d_a_output = $a_output;
}
$template_file = "QuickTestTemplate.rtf";
$handle = fopen($template_file , "r");
$contents = fread($handle, filesize($template_file));
$original= array("TestNumberHere", "TestQuestionsHere", "TestAnswersHere");
$new_questions = implode('',$d_q_output);
$new_answers = implode('',$d_a_output);
$new = array("$counter", $new_questions, $new_answers);
$newcontents = str_replace($original, $new, $contents);
$newcontents = str_replace(" ", " ", $newcontents);
$newcontents = str_replace("<br>", "\n", $newcontents);
fwrite($new_doc ,$newcontents);
fclose ($new_doc);
}
fclose($handle);
Also, how do I make a new line in for the Word Document that is being created because \n doesn't seem to be working....
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Sun Sep 09, 2007 6:36 am
tecktalkcm0391 wrote: Also, how do I make a new line in for the Word Document that is being created because \n doesn't seem to be working....
"\n" is Linux.
"\r" is Mac.
"\r\n" is Windows.
I think.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Sep 09, 2007 8:04 am
The constant PHP_EOL is set for the server's native carriage return.