Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.