irandoct Posted September 10, 2015 Share Posted September 10, 2015 Hi,I'm trying to output a text file using php. how may i set this file as ascii?this is my code: function export_listnm(){ global $conn, $Language, $Security; $sdate = preg_replace('/-|:/', null, $_GET['sdate']); $edate = preg_replace('/-|:/', null, $_GET['edate']); $MedicalCouncilNumber = strip_tags(ew_ExecuteScalar("SELECT ConfigValue FROM configs WHERE ConfigKey = 'MedicalCouncilNumber'")); $NIDCode = strip_tags(ew_ExecuteScalar("SELECT ConfigValue FROM configs WHERE ConfigKey = 'NIDCode'")); $MainStaffName = strip_tags(ew_ExecuteScalar("SELECT ConfigValue FROM configs WHERE ConfigKey = 'MainStaffName'")); $MainStaffLastName = strip_tags(ew_ExecuteScalar("SELECT ConfigValue FROM configs WHERE ConfigKey = 'MainStaffLastName'")); $tedadnoskheh = ew_ExecuteScalar("SELECT COUNT(TreatmentID) FROM treatmenthistory WHERE ReportDate >= '".$_GET['sdate']."' AND ReportDate <= '".$_GET['edate']."' AND InsuranceID = '".$_GET['insurance']."'"); $sitename = ew_ExecuteScalar("SELECT ConfigValue FROM configs WHERE ConfigKey = 'SiteName'"); $insurance = ew_ExecuteScalar("SELECT InsuranceName FROM insurances WHERE InsuranceID = '".$_GET['insurance']."'"); $inscode = ew_ExecuteScalar("SELECT InsCode FROM insurances WHERE InsuranceID = '".$_GET['insurance']."'"); $cliniccode = ew_ExecuteScalar("SELECT ClinicCode FROM insurances WHERE InsuranceID = '".$_GET['insurance']."'"); $Percentage = ew_ExecuteScalar("SELECT Percentage FROM insurances WHERE InsuranceID = '".$_GET['insurance']."'"); $conn->Execute("SET @row_num = 0;"); $sSqlWrk = "SELECT @row_num := @row_num + 1 as row_number, treatmenthistory.*, referrers.RefName, referrers.MedicalCouncil, patients.FullName, patients.gender FROM treatmenthistory join referrers on treatmenthistory.RefID = referrers.RefID join patients on treatmenthistory.PatientID = patients.PatientID WHERE treatmenthistory.ReportDate >= '".$_GET['sdate']."' AND treatmenthistory.ReportDate <= '".$_GET['edate']."' AND InsuranceID = '".$_GET['insurance']."' ORDER BY treatmenthistory.ReceptionDate ASC"; $theres = $conn->Execute($sSqlWrk); if (!file_exists('insurancereports')) { mkdir('insurancereports', 0777, true); } $f = fopen("insurancereports/insurance.txt", "a"); fwrite($f, "<Y>\n"); fwrite($f, "<HR>\n"); fwrite($f, "<DC>".$cliniccode."</DC>\n"); fwrite($f, "<DN>".$sitename."</DN>\n"); fwrite($f, "<CR>kimia System 09133999236</CR>\n"); fwrite($f, "<RC>".$tedadnoskheh."</RC>\n"); fwrite($f, "<FD>".$sdate."</FD>\n"); fwrite($f, "<TD>".$edate."</TD>\n"); fwrite($f, "<MC>".$MedicalCouncilNumber."</MC>\n"); fwrite($f, "<NM>".$NIDCode."</NM>\n"); fwrite($f, "<AN>".$MainStaffName."</AN>\n"); fwrite($f, "<AF>".$MainStaffLastName."</AF>\n"); fwrite($f, "</HR>\n"); while (!$theres->EOF) { $row = ew_ExecuteRow("SELECT SUM(ExPriceIns) AS ExPriceIns FROM treatmentdetails WHERE TreatmentID = '".$theres->fields('TreatmentID')."'"); $fullprice = $row["ExPriceIns"]; $patientprice = $fullprice * $Percentage /100; $insprice = $fullprice - $patientprice; if ($theres->fields('gender') == "F"){ $gender = "0"; }else if ($theres->fields('gender') == "M"){ $gender = "1"; } $orderdate = preg_replace('/-|:/', null, $theres->fields('InsOrderDate')); $insuranceenddate = preg_replace('/-|:/', null, $theres->fields('InsEndDate')); $firstsession = ew_ExecuteScalar("SELECT VisitDay FROM appointments WHERE TreatmentID = '".$theres->fields('TreatmentID')."' AND IsCanceled = 'N' ORDER BY VisitDay ASC LIMIT 1"); $firstsession = preg_replace('/-|:/', null, $firstsession); $lastsession = ew_ExecuteScalar("SELECT VisitDay FROM appointments WHERE TreatmentID = '".$theres->fields('TreatmentID')."' AND IsCanceled = 'N' ORDER BY VisitDay DESC LIMIT 1"); $lastsession = preg_replace('/-|:/', null, $lastsession); fwrite($f, "<X>\n"); fwrite($f, "<PH>\n"); fwrite($f, "<SQ>".$theres->fields('row_number')."</SQ><ND>".$orderdate."</ND><RD>".$firstsession."</RD><LD>".$lastsession."</LD><VD>".$insuranceenddate."</VD><PT>".$inscode."</PT><SN>".$theres->fields('InsuranceNumber')."</SN><GR>".$gender."</GR><RN>".$theres->fields('InsPageNumber')."</RN><PG>1</PG><PC>".$theres->fields('MedicalCouncil')."</PC><DD>18</DD><PP>".$fullprice."</PP><IS>".$insprice."</IS><PS>".$patientprice."</PS>\n"); fwrite($f, "</PH>\n"); $sSqlWrk2 = "SELECT treatmentdetails.*, products.ProductCode FROM treatmentdetails join products on treatmentdetails.ProductID = products.ProductID WHERE treatmentdetails.TreatmentID = '".$theres->fields('TreatmentID')."' AND treatmentdetails.ShowInList = 'Y'"; $theres2 = $conn->Execute($sSqlWrk2); while (!$theres2->EOF) { $sahmbimeh = $theres2->fields('ExPriceIns') * $Percentage / 100; $sahmbimar = $theres2->fields('ExPriceIns') - $sahmbimeh; fwrite($f, "<MH><MG>".$theres2->fields('ProductCode')."</MG><OZ></OZ><NG>".$theres2->fields('Quantity')."</NG><NA>".$theres2->fields('BodyAreaIns')."</NA><FC>".$MedicalCouncilNumber."</FC><TK>1</TK><MD>".$theres2->fields('Quantity')."</MD><MR>".$theres2->fields('Quantity')."</MR><MP>".$theres2->fields('ExPriceIns')."</MP><MI>".$sahmbimeh."</MI><MS>".$sahmbimar."</MS></MH>\n"); $theres2->MoveNext(); } $theres2->Close(); fwrite($f, "<BY>\n"); fwrite($f, "</BY>\n"); fwrite($f, "</X>\n"); $theres->MoveNext(); } $theres->Close(); fwrite($f, "</Y>\n"); fclose($f); echo "<br><br>"; echo "<a href=insurancereports/insurance.txt>Download</a>"; echo "<br><br><br><br>"; } please help me save the text file as ascii! Thank you Mansour Quote Link to comment https://forums.phpfreaks.com/topic/298125-create-an-ascii-text-file-with-php/ Share on other sites More sharing options...
ginerjm Posted September 10, 2015 Share Posted September 10, 2015 Have you read anything in the php manual that sounds like it might help? Quote Link to comment https://forums.phpfreaks.com/topic/298125-create-an-ascii-text-file-with-php/#findComment-1520638 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.