Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,872 questions

51,796 answers

573 users

How to read text file character by character with PHP

2 Answers

0 votes
$f = fopen("e:/numbers.txt", "r") or die("Error open file!");
while(!feof($f)) 
{
   echo fgetc($f);
}
fclose($f);


/*
run:

1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 

*/

 



answered Dec 3, 2015 by avibootz
edited Dec 5, 2015 by avibootz
0 votes
$f = fopen("e:/numbers.txt", "r") or die("Error open file!");
$ch;
while(!feof($f)) 
{
    $ch = fgetc($f);
    if ($ch == "\n") // "\n" is the end of line
        echo "<br />";
    else
        echo $ch;
}
fclose($f);


/*
run:

1.0 
2.0 
3.0 
4.0 
5.0 
6.0 
7.0 
8.0 
9.0 
10.0 

*/

 



answered Dec 3, 2015 by avibootz
edited Dec 5, 2015 by avibootz

Related questions

2 answers 283 views
283 views asked Jan 4, 2021 by avibootz
1 answer 235 views
235 views asked Jun 29, 2014 by avibootz
1 answer 202 views
1 answer 147 views
...