How to read a file and assign its content to a variable using PHP?

Mujkanovic

Well-known member
Collaborate
Registered
Joined
Apr 24, 2016
Messages
430
Points
18
I have a large data in a file .txt
How can I use PHP to read the content in this file and assign it to a variable?
 

fwh

Administrator
Staff Member
Joined
Dec 8, 2012
Messages
773
Points
63
How can I use PHP to read the content in this file and assign it to a variable?
This code works

Code:
<?php
if ($fh = fopen('filename.txt', 'r')) {
    while (!feof($fh)) {
        $varcon= fgets($fh);
        echo $varcon;
    }
    fclose($fh);
}
?>
It will assign all content in filename.txt into $varcon
 
Older Threads
Replies
1
Views
1,986
Replies
2
Views
4,303
Replies
1
Views
3,616
Latest Threads
Replies
0
Views
567
Replies
2
Views
537
Replies
1
Views
480
Replies
2
Views
1,065
Replies
1
Views
691
Recommended Threads
Replies
20
Views
14,466
Replies
1
Views
4,025
Replies
7
Views
5,568
Replies
11
Views
4,446
Replies
15
Views
8,604

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top