nicob Posted June 15, 2008 Share Posted June 15, 2008 I'm trying something out, but I can't get the right result. I try to combine 2 codes... file.txt contains something like this: marc peter ellen martin petra ... ------------------------------------------ Code 1: includes 'file.txt' en shows only the LAST 10 lines from that text file. <?php $file = "file.txt"; echo implode("",array_slice(file("$file"),-10,10)); ?> ------------------------------- code2: includes 'file.txt', looks for duplicates + replaces something (important for me), and then it shows the WHOLE list without duplicates. <?php $file = "file.txt"; $nodups = array_unique (explode ("\n", str_replace("\n | ", "", file_get_contents($file)))); echo implode ("\n", $nodups); ?> ************************ Now I want to combine this 2 codes so I'll end with: inlcudes 'file.txt', looks for duplicates + replaces something (important for me), and then it shows only the 10 last lines (now without dups). But I have a problem with the 2 'echo implodes'. How do you combine 2 echo implodes from 2 diff codes? not working code with DOUBLE 'echo implode' <?php $file = "file.txt"; $nodups = array_unique (explode ("\n", str_replace("\n | ", "", file_get_contents($file)))); echo implode ("\n", $nodups); echo implode("",array_slice(file("$bestand"),-10,10)); ?> Link to comment https://forums.phpfreaks.com/topic/110334-solved-2-small-codes-make-this-newbie-crazy/ Share on other sites More sharing options...
thebadbad Posted June 15, 2008 Share Posted June 15, 2008 Instead of array_slice'ing the returned array from file(), slice the $nodups array: <?php $file = "file.txt"; $nodups = array_unique (explode ("\n", str_replace("\n | ", "", file_get_contents($file)))); echo implode("\n",array_slice($nodups,-10,10)); ?> Link to comment https://forums.phpfreaks.com/topic/110334-solved-2-small-codes-make-this-newbie-crazy/#findComment-566100 Share on other sites More sharing options...
nicob Posted June 15, 2008 Author Share Posted June 15, 2008 Thx thebadbad! now it works. Link to comment https://forums.phpfreaks.com/topic/110334-solved-2-small-codes-make-this-newbie-crazy/#findComment-566114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.