jamesxg1 Posted July 18, 2009 Share Posted July 18, 2009 Ok the code is short very! so i dont need to really explain what i am trying to do, test.php <?php $textfile = 'datafiles.rtf'; $handle = fopen("$textfile", "r"); $contents = fread($handle, filesize($textfile)); fclose($handle); echo nl2br($contents); echo "<BR>"; $det = preg_split("/[\s,]+/", "$contents"); print_r($det); ?> write.php <?php foreach(glob("*.php") as $filename) { $contents .= $filename . '-' . filesize($filename) . "\r" ; } file_put_contents("datafiles.rtf", $contents); ?> datafiles.rtf connect.php-7722 db.php-1482 test.php-281 write.php-180 Screen Print connect.php-7722 db.php-1482 test.php-281 write.php-180 Array ( [0] => connect.php-7722 [1] => db.php-1482 [2] => test.php-281 [3] => write.php-180 [4] => ) i need to turn $det into and array like so array($FILENAME => $SIZE) with all the details on the files in one array basically i need to remove the " - " from the .rtf file (implode, explode, split, str_replace) anything i am just really stuck here James. Quote Link to comment https://forums.phpfreaks.com/topic/166432-i-need-array-help/ Share on other sites More sharing options...
jamesxg1 Posted July 18, 2009 Author Share Posted July 18, 2009 Anyone ??? Quote Link to comment https://forums.phpfreaks.com/topic/166432-i-need-array-help/#findComment-877651 Share on other sites More sharing options...
Michdd Posted July 18, 2009 Share Posted July 18, 2009 $split = explode("\n", $string); foreach($split as $part) { $parts = explode('-', $part); $info[$parts[0]] = $parts[1]; } Where $string is the contents of the file. Quote Link to comment https://forums.phpfreaks.com/topic/166432-i-need-array-help/#findComment-877666 Share on other sites More sharing options...
wildteen88 Posted July 18, 2009 Share Posted July 18, 2009 test.php <?php $textfile = 'datafiles.rtf'; $handle = fopen("$textfile", "r"); $contents = fread($handle, filesize($textfile)); fclose($handle); echo nl2br($contents); echo "<BR>"; $det = preg_split("/[\s,]+/", "$contents"); print_r($det); ?> That can be written as $contents = file('datafiles.rtf'); $contents = array_map('trim', $contents); foreach($contents as $line) { list($filename, $size) = explode('-', $line); $files[$filename] = $size; } echo '<pre>'.print_r($files, true).'</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/166432-i-need-array-help/#findComment-877673 Share on other sites More sharing options...
jamesxg1 Posted July 18, 2009 Author Share Posted July 18, 2009 test.php <?php $textfile = 'datafiles.rtf'; $handle = fopen("$textfile", "r"); $contents = fread($handle, filesize($textfile)); fclose($handle); echo nl2br($contents); echo "<BR>"; $det = preg_split("/[\s,]+/", "$contents"); print_r($det); ?> That can be written as $contents = file('datafiles.rtf'); $contents = array_map('trim', $contents); foreach($contents as $line) { list($filename, $size) = explode('-', $line); $files[$filename] = $size; } echo '<pre>'.print_r($files, true).'</pre>'; hiya mate, this seems to be very effective , but the only problem is, is that it is showing of the details of one file (one line) this is the screen print Array ( [connect.php] => 7722 db.php ) Quote Link to comment https://forums.phpfreaks.com/topic/166432-i-need-array-help/#findComment-877680 Share on other sites More sharing options...
wildteen88 Posted July 19, 2009 Share Posted July 19, 2009 Oh the issue is with write.php. Change this line $contents .= $filename . '-' . filesize($filename) . "\r" ; To $contents .= $filename . '-' . filesize($filename) . "\n" ; Run write.php followed by test.php. Quote Link to comment https://forums.phpfreaks.com/topic/166432-i-need-array-help/#findComment-877965 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.