⊗ppPmFSFRe 331 of 447 menu

Reading Files in PHP

The function file_get_contents allows reading a file. The function takes the filename as a parameter and returns the text of that file as its result.

Let's see it in practice. Suppose we have a file index.php, which we access through the browser. Let also in this same folder there is a file test.txt.

Let's read the text of the text file and display this text on the screen:

<?php echo file_get_contents('test.txt'); ?>

Suppose you have files 1.txt and 2.txt, in which some numbers are written. Write a script that will display the sum of the numbers written in these files.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline