1 / 15

การพัฒนาโปรแกรมประยุกต์บนเว็บ

การพัฒนาโปรแกรมประยุกต์บนเว็บ. แฟ้มข้อความ (Text File) #1. มหาวิทยาลัยโยนก จังหวัดลำปาง ศูนย์กลางความรู้และภูมิปัญญาแผ่นดิน http://www.yonok.ac.th. อ.บุรินทร์ รุจจนพันธุ์ . ปรับปรุง 3 กรกฎาคม 2550. แฟ้มข้อความ (Text File).

Download Presentation

การพัฒนาโปรแกรมประยุกต์บนเว็บ

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. การพัฒนาโปรแกรมประยุกต์บนเว็บการพัฒนาโปรแกรมประยุกต์บนเว็บ แฟ้มข้อความ (Text File) #1 มหาวิทยาลัยโยนก จังหวัดลำปาง ศูนย์กลางความรู้และภูมิปัญญาแผ่นดิน http://www.yonok.ac.th อ.บุรินทร์ รุจจนพันธุ์ . ปรับปรุง 3 กรกฎาคม 2550

  2. แฟ้มข้อความ (Text File) เว็บไซต์ส่วนใหญ่มีระบบจัดการฐานข้อมูลเช่น MySQL, MS-Access, SQL Server แต่ถ้าไม่มีระบบเหล่านี้ให้บริการ หรือทำงานเล็ก ๆ ขึ้นมาสักงาน อาจเลือกใช้ Text file สำหรับเก็บข้อมูลแทนได้ Slide ชุดนี้ แสดงตัวอย่างให้เห็นวิธีจัดการกับแฟ้มเหล่านี้เช่น เลือกข้อมูล เพิ่มข้อมูล ลบข้อมูล ปรับปรุงข้อมูล หรือสร้างแฟ้มใหม่

  3. ตัวอย่างแฟ้มข้อมูล x.txt 101,200 102,150 103,180 104,600

  4. อ่านแฟ้มเข้าอาร์เรย์มาแสดงอ่านแฟ้มเข้าอาร์เรย์มาแสดง <? $ar = file("x.txt"); foreach ($ar as $v){ echo $v; } ?>

  5. อ่านข้อมูลมาแสดง แต่เปลี่ยน 600 เป็น 120 <pre> <? $ar = file("x.txt"); foreach ($ar as $v){ $x = str_replace("600","120",$v); echo $x; } ?>

  6. อ่านแฟ้มแล้วเลือกเฉพาะรหัสผู้ใช้อ่านแฟ้มแล้วเลือกเฉพาะรหัสผู้ใช้ <? $ar = file("x.txt"); foreach ($ar as $v){ $k = split(",",$v); echo $k[0]."<br>"; } ?>

  7. อ่านแฟ้มมาแสดงผล (1/2) <? $f = fopen("x.txt","r"); while(!feof($f)){ $d = fgets($f,1000); echo "$d<hr color=red>"; } fclose($f); ?>

  8. อ่านแฟ้มมาแสดงผล (2/2) <? if (file_exists("x.txt")) { $f = fopen("x.txt","r"); while(!feof($f)){ $d=fgets($f,2);//1 will error echohtmlspecialchars($d); } fclose($f); } ?>

  9. เขียนข้อมูลเข้าไปในแฟ้มใหม่ หรือทับ <? $f = fopen("x.txt","w"); fputs($f,"101,200\n"); fputs($f,"102,150\n"); fputs($f,"103,180\n"); fclose($f); ?>

  10. เขียนข้อมูลเพิ่มเข้าแฟ้มเดิมเขียนข้อมูลเพิ่มเข้าแฟ้มเดิม <? $f = fopen("x.txt","a"); fputs($f,"104,600\n"); fclose($f); ?>

  11. อ่านแฟ้มข้อมูลแล้วเขียนทับแฟ้มเดิมอ่านแฟ้มข้อมูลแล้วเขียนทับแฟ้มเดิม <? $ar = file("x.txt"); $f = fopen("x.txt","w"); foreach ($ar as $v) { fputs($f,"$v"); } fclose($f); ?>

  12. อ่านแฟ้มข้อมูลแล้วลบตามเลขบรรทัดอ่านแฟ้มข้อมูลแล้วลบตามเลขบรรทัด <? $ar = file("x.txt"); $f = fopen("x.txt","w"); for($i=0;$i<count($ar);$i++) { if ($i != 2) fputs($f,$ar[$i]); } fclose($f); ?>

  13. อ่านแฟ้มแล้วลบตามรหัสพนักงานอ่านแฟ้มแล้วลบตามรหัสพนักงาน <? $did = 102; // $_REQUEST[“id”]; $ar = file("x.txt"); $f = fopen("x.txt","w"); for($i=0;$i<count($ar);$i++) { $k = split(",",$ar[$i]); if ($k[0] != $did) fputs($f,$ar[$i]); } fclose($f); ?>

  14. อ่านแฟ้มแล้วเปลี่ยนตามรหัสพนักงานอ่านแฟ้มแล้วเปลี่ยนตามรหัสพนักงาน <? $eid = 104; // $_REQUEST[“id”]; $esala = 999; // $_REQUEST[“sala”]; $ar = file("x.txt"); $f = fopen("x.txt","w"); for($i=0;$i<count($ar);$i++) { $k = split(",",$ar[$i]); if ($k[0] == $eid) fputs($f,"$eid,$esala\n"); else fputs($f,$ar[$i]); } fclose($f); ?>

  15. Text Conversion $a = “abc”; echo stripslashes($a)."\n"; // Un-quote string quoted with addslashes() echo addslashes($a)."\n"; // Quote string with slashes echo urlencode($a)."\n"; // URL-encodes string echo urldecode(urlencode($a))."\n"; // Decodes URL-encoded string echo htmlspecialchars($a)."\n"; // Convert special characters to HTML entities echo htmlentities($a)."\n"; // Convert all applicable characters to HTML entities echo base64_encode($a)."\n"; // Encodes data with MIME base64 echo base64_decode(base64_encode($a))."\n"; // Decodes with MIME base64 echo crypt($a)."\n"; // One-way string encryption (hashing) (ผลไม่ซ้ำกัน) ข้อมูลจาก http://www.thaiall.com/php

More Related