วันศุกร์ที่ 26 เมษายน พ.ศ. 2562

PHP สร้าง Text File // อ่าน Text File

การสร้าง Text File
<?php
$myfile = fopen("sk_fore.txt", "w") or die("Unable to open file!");
$txt = number_format($row_rs_eff2for[forebay],2);
fwrite($myfile, $txt);
$txt = "|".$row_rs_eff2for[eff_storage];
fwrite($myfile, $txt);
$txt = "|".$row_rs_eff2for_ncc[forebay];
fwrite($myfile, $txt);
$txt = "|".$row_rs_eff2for_ncc[eff_storage];
fwrite($myfile, $txt);


fclose($myfile);
?> 


การอ่าน Text File

    <?php
            $myFile = "../../sk/sk_fore.txt";
            $fh = fopen($myFile, 'r');
            $theData = explode("|",fread($fh, filesize($myFile)));
            fclose($fh);
        ?>


นำไปแสดงผล
    <tr>
        <td colspan="3" rowspan="3" background="images/sk_graphic4_65.gif"><input name="textfield" type="text" class="style11" value="<?=number_format($theData[1],2);?>"  size="8" maxlength="10"> </td>

ไม่มีความคิดเห็น:

แสดงความคิดเห็น