ขอ สคลิป การบันทึกข้อมูล ลง Text file หน่อยได้มะครับ

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: ขอ สคลิป การบันทึกข้อมูล ลง Text file หน่อยได้มะครับ

โดย whiteman20 » 23/04/2007 8:23 pm

โหะๆๆ ขอบคุณมากครับ อยุ่หน้าจอตลอดเลยหรอ ดีจัง เด๋ว มีข้อสงสัยอะไร ถามใหม่นะครับ ชอบเวบนีจิงๆหุหุ บริการประทับใจ

โดย mindphp » 23/04/2007 8:14 pm

ถ้า php 4 จะเขียนไฟล์ ก็ ตามนี้นะครับ จากคู่มือ php
<?php
$filename = 'test.txt';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}

// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($somecontent) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}
?>

โดย mindphp » 23/04/2007 8:11 pm

file_get_contents ใช้ได้กับ php 4.3 เป็นต้นมา ครับ
แต่
file_put_contents ใช้ได้กับ php5 นะครับ

โดย whiteman20 » 23/04/2007 8:10 pm

ลืมบอก ไปครับ ผมใช้php4อ่ะ ใช้ฟังก์ชั่นเหมือนกันรึป่าวครับ

โดย whiteman20 » 23/04/2007 7:48 pm

ขอบคุณมาก ครับ ที่ตอบ รวดเร็วดีจังเลย ถึงจะงงๆอยู่ซักหน่อย แต่ก็ขอบคุณครับ

โดย mindphp » 23/04/2007 5:29 pm

ต้อง พึ่ง function ที่ php มีอยู่ ล่ะครั บ
ถ้าเอา แบบ ง่ายๆ สุด แบบ php 5 ก็
file_put_contents ( string filename, mixed data )
โดยที่ string filename คือ ชื่อไฟล์ที่เราต้อง การเขียน
mixed data คือ ข้อความ ของ เรา ที่ จะเขียนลงไป ครับ

ส่วนการอ่าน ข้อมูล จากไฟล์ ก็
file_get_contents ( string filename)
จะคือ ค่าออกมาเป็น string ครับ

ขอ สคลิป การบันทึกข้อมูล ลง Text file หน่อยได้มะครับ

โดย whiteman20 » 23/04/2007 5:08 pm

ผม ขอ สคลิป การบันทึกข้อมูล ลง Text file หน่อยได้มะครับ คือ ผมอยากทราบว่าจะต้องใช้สคลิป
อะไรบ้าง อย่างเช่น การกรอก Form แล้วให้ไปเก็บไว้ใน Text File แล้วสามารถมีการเรียกดู ข้อมูล ที่บันทึก ใน Text file ด้วยอ่ะครับ ถ้าไม่ลำบาก เกินไปขอรบกวนหน่อยครับ ไม่รู้จะไป พึ่งพาใครแล้ว T_T

ข้างบน