PHP Loop Put Contents Of File In Box

Associate
Joined
7 Aug 2012
Posts
948
Hi All,

I was wondering if this was possible?

I'm after a function which will loop through a folder and read each text file and place them in their own box/div which have a vertical scroll as these text files are pretty big.

I have the loop working and I can get it to display all the text, however I'm struggling on how to split the text up to make it easier to read.

Code:
foreach (glob("D:/Testing/*.txt") as $filename) {

    echo nl2br( file_get_contents($filename) );
}


Any help would be appreciated :)

Cheers

Swain90
 
Last edited:
Associate
Joined
24 May 2011
Posts
262
Can't you just echo some div tags around the output? You could then style the divs so that they have scrollbar etc

PHP:
foreach (glob("D:/Testing/*.txt") as $filename) {
    echo "<div>";
    echo nl2br( file_get_contents($filename) );
    echo "</div>";
}
 
Associate
OP
Joined
7 Aug 2012
Posts
948
Code:
foreach (glob("D:/Testing/*.txt") as $filename) {
echo "<div style='overflow:auto; width:400px;height:400px;'>";
echo nl2br (file_get_contents($filename));
echo "</div>";
}

I've tried this and no luck. Not sure if it makes any difference but I'm using this within WordPress. The PHP plugin seems to be working ok as the looping of the text files work, it just seems to have problems processing any HTML within the php code.
 
Associate
OP
Joined
7 Aug 2012
Posts
948
Eurgggghhhhhhh

It was the plugin that wasn't working properly.


Just for future reference I was using "Allow PHP in Posts" which DOESN'T allow HTML.

Now currently using Insert PHP
 
Last edited:
Back
Top Bottom