Jump to content

[SOLVED] get file contents and splitting problem :(


jamesxg1

Recommended Posts

Ok this is my script,

 

<?php

$textfile = 'datafiles.txt';

$handle = fopen("$textfile", "r");

$contents = fread($handle, filesize($textfile));

list($filename, $size) = split(" - ", $contents);

fclose($handle);

print $filename . " - " . $size . PHP_EOL . "<br>";


?>

 

This is the 'datafiles.txt' file contents,

 

test.php - 153
write.php - 202

 

but when i run the script all i get is this,

 

test.php - 153 write.php

 

^^ that's one line ^^

 

i am very confused :(,

 

does anyone have any ideas to why ?,

 

Many thanks,

 

James.

Well, what's your expected output? Telling us that would help explain how to get what you want. To answer you question directly your problem is that your variable $size contains "153 write.php". So you're calling the PHP_EOL/<br> after everything.

Well, what's your expected output? Telling us that would help explain how to get what you want. To answer you question directly your problem is that your variable $size contains "153 write.php". So you're calling the PHP_EOL/<br> after everything.

 

 

Ok, well basically what i need is an output like this,

 

FILENAME - FILESIZE

FILENAME - FILESIZE

 

if you get what i mean :),

 

but i really dont understand how to do this,

 

this is my first time with php file system functions :).

Well, what's your expected output? Telling us that would help explain how to get what you want. To answer you question directly your problem is that your variable $size contains "153 write.php". So you're calling the PHP_EOL/<br> after everything.

 

 

Ok, well basically what i need is an output like this,

 

FILENAME - FILESIZE

FILENAME - FILESIZE

 

if you get what i mean :),

 

but i really dont understand how to do this,

 

this is my first time with php file system functions :).

Is the number next to it in the file the "FILESIZE" that you want outputted? Or do you want it recalculated?

Well, what's your expected output? Telling us that would help explain how to get what you want. To answer you question directly your problem is that your variable $size contains "153 write.php". So you're calling the PHP_EOL/<br> after everything.

 

 

Ok, well basically what i need is an output like this,

 

FILENAME - FILESIZE

FILENAME - FILESIZE

 

if you get what i mean :),

 

but i really dont understand how to do this,

 

this is my first time with php file system functions :).

Is the number next to it in the file the "FILESIZE" that you want outputted? Or do you want it recalculated?

 

 

Its already on the text file ill attach it :)

 

[attachment deleted by admin]

If it's already in the text file then it sounds like you want to output the exact contents of the file?

 

<?php
$textfile = 'datafiles.txt';
$handle = fopen("$textfile", "r");
$contents = fread($handle, filesize($textfile));
fclose($handle);

echo nl2br($contents);

 

Or am I wrong?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.