Php text file
This presentation is the property of its rightful owner.
Sponsored Links
1 / 19

การใช้ PHP ติดต่อกับ Text File PowerPoint PPT Presentation


  • 67 Views
  • Uploaded on
  • Presentation posted in: General

การใช้ PHP ติดต่อกับ Text File. เสรี ชิโนดม [email protected] การเปิดไฟล์. ใช้คำสั่ง fopen มีรูปแบบดังนี้ int fopen(“ พาธและชื่อไฟล์ ”, “ โหมดการเปิดไฟล์ ”)

Download Presentation

การใช้ PHP ติดต่อกับ Text File

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Php text file

PHP Text File

[email protected]


Php text file

  • fopen

    int fopen(, )

  • file file system return file pointer file function return

  • mode

    • 'r' - , file pointer file

    • 'r+' - , file pointer file

PHP Programming


Php text file

  • 'w' - , file pointer file file file file

  • 'w+'- , file pointer file file file file

  • 'a' - , file pointer file (EOF:end of file) file file

  • 'a+' - , file pointer file (EOF:end of file) file

PHP Programming


Php text file

$FILE = fopen(config.inf, r);

//

if (!$FILE) {

echo <H1> ERROR, file not found </H1> ;

} else {

print (File Found);

}

PHP Programming


Php text file

  • fclose file pointer return file pointer

    int fclose(int fp)

  • $FILE = fopen(config.inf, r);

    ..

    fclose($FILE);

PHP Programming


Php text file

  • string fread (, )

    string fgets (, )

    string fgetss (, )

  • 3

PHP Programming


Fread1 php

fread1.php

<?

$FILE = fopen( "info.txt" , "r" );

$text =fread($FILE, 20 );

print ($text <BR>);

fclose( $FILE );

?>

PHP Programming


Fgets fgetss

fgets, fgetss

  • fgets 1

    <?

    $FILE = fopen( "info.txt" , "r" );

    echo Each time read 20 characters <P> ;

    $text =fgets($FILE, 20 );

    print (data = $text <BR>);

    fclose( $FILE );

    ?>

PHP Programming


Fgets fgetss1

fgets, fgetss

  • fgetss fgets HTML

    <?

    $FILE = fopen( bookmark.htm" , "r" );

    while (!feof($FILE) {

    $text =fgetss($FILE, 255 );

    print ($text <BR>) ;

    }

    fclose( $FILE );

    ?>

PHP Programming


Php text file

  • fgetc

  • <?

    $FILE = fopen( "info.txt" , "r" );

    $char = fgetc($FILE);

    print (Character is $char);

    fclose( $FILE );

    ?>

PHP Programming


Php text file

<?

$FILE = fopen( "info.txt" , "r" );

while (!feof($FILE) {

$char = fgetc($FILE);

print ($char) ;

}

fclose( $FILE );

?>

feof()

PHP Programming


Php text file

  • a

    <?

    $FILE = fopen( "info.txt" , "r" );

    while (!feof($FILE) {

    print (" $char ") ;

    $char = fgetc($FILE);

    if(($char == "a" ||($char == "A" )){

    $a++

    }

    }

    fclose( $FILE );

    print "<BR><BR> Have a = $a";

    ?>

PHP Programming


Php text file

  • int fwrite(,,)

  • int fputs(,,)

  • <?

    $FILE = fopen("myinfo" , "w" );

    fputs( $FILE, "My name is Oh");

    echo "write file" ;

    fclose( $FILE );

    ?>

PHP Programming


Php text file

  • $fname =somsak ;

  • $lname=sansook;

  • fputs($FILE, My name is $fname.\r\n);

  • fputs($FILE, My name is $lname.\r\n);

PHP Programming


Php text file

<?

$data = file("info.txt");//info.txt

$FILE = fopen( "info.htm" , "w" );

fputs( $FILE , "<html><body>" );

fputs( $FILE , "<font color=blue>" );

for ( $i=0; $i<count($data) ; $i++ )

{

fputs( $FILE , $data[$i] . "<br>" );

}

fputs( $FILE , "</html></body>" );

fclose( $FILE );

echo "write info.htm in HTML format";

?>

PHP Programming


Rewind

rewind

  • file pointer

    <?

    $FILE = fopen( "info.txt" , "r" );

    $text =fgets($FILE, 50);

    print "text is $text <BR>";

    rewind( $FILE );

    $text =fgets($FILE, 50);

    print "Again text is $text <BR>";

    fclose( $FILE );

    ?>

PHP Programming


F seek

fseek

  • file pointer 101-150 info.txt

    <?

    $FILE = fopen( "info.txt" , "r" );

    fseek($FILE, 101);

    $text =fgets($FILE, 50);

    print "text is <U>$text </U>";

    fclose ($FILE);

    ?>

PHP Programming


Ftell

ftell

  • file pointer

    <?

    $FILE = fopen( "info.txt" , "r" );

    $pos = ftell($FILE);

    print "Position is <U>$pos </U>";

    fclose(($FILE);

    ?>

PHP Programming


Php text file

  • file_exits

  • file_size

    <?

    $f = "info.txt ;

    if ( file_exits( $f ) ) {

    print Found $f ;

    } else {

    print Not found $f ;

    ?>

PHP Programming


  • Login