Search In This Website

Rabu, 16 Oktober 2024

Read File In PHP 1

Preparation Step

  1. type this data in editor
    Didi   0458-665-290
    John   07-871-12
    Mary   07-9997-3366
    Steve  03-8174-9123
    Smith  0458-111-113
  2. and save as phonebook.txt. Or you can download file text on phonebook.txt ( box )

Coding Step

  1. type this following PHP code in your PHP editor / web editor:
    <?php
    $filename = 'phonebook.txt';
    if (file_exists($filename)) {
    $fh = fopen($filename,'r');
    if ($fh) {
    while ($line = fgets($fh)) {
    echo($line.'<br/>');
    }
    }
    fclose($fh);
    } else {
    echo "file not exist";
    }
    ?>
  2.  and save as readTextFile1.php. Or you can download the source code file on readTextFile1.php ( bitbucket )

Running Step

  1. Running your PHP Web Server, such as XAMPP. If you want to learn how to start XAMPP, click Hello World PHP XAMPP.
  2. Open your Internet Browser.
  3. Type your local host address, such as http://localhost/readTextFile1.php.
  4. Press Enter.
  5. Then you can see the result in browser.

<< back to Study About PHP 1

Bibliography

  • https://daily.dev/
  • https://devdocs.io/
  • https://dev.mysql.com/ ( manual ebook )
  • https://www.php.net/manual/ ( manual ebook )

Related Post

Tidak ada komentar:

Posting Komentar