[PHP] IO operation in PHP!

Source: Internet
Author: User
<?php//The first way to read the file $file _path = "Db.ini";

        Determine if the file exists (must be judged) if (file_exists ($file _path)) {//Open file, specify file path, read mode $fp = fopen ($file _path, "A +");

        Read length $con = fread ($fp, FileSize ($file _path));

        The replacement character//php does not deal with special characters and needs to be converted $con = Str_replace ("\ n", "<br/>", $con);
    Echo $con;
    }else{echo "file does not exist";

    //close file, must fclose ($FP);
        The second way to read the file, automatically closes the file//direct access to the file content//To determine whether the file exists (must be judged) if (file_exists ($file _path)) {//directly get the contents of the file

        $con = file_get_contents ($file _path);

        Substitution character $con = str_replace ("\ n", "<br/>", $con);
    Echo $con;
    }else{echo "file does not exist";

        //I will close the file///Third way to read the file//while Circular read, suitable for large files//To determine whether the file exists (must be judged) if (file_exists ($file _path)) {
        Open File $fp = fopen ($file _path, "A +");
        $str = "";

        $buffer = 1024;
       While loop read, suitable for large file while (!feof ($fp)) {     $str = Fread ($fp, $buffer);
            $str = Str_replace ("\ n", "<br/>", $str);
        Echo $str;
    //close file, must fclose ($FP);
    }else{echo "file does not exist";

        The//fourth read file (automatically closes file) if (file_exists ($file _path)) {$arr = Parse_ini_file ("Db.ini");

        Print_r ($arr);
    mysql_connect ($arr [' Host '], $arr [' User '], $arr [' Password ']);
    }else{echo "file does not exist";
 }?> </body> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.