nicob Posted November 28, 2008 Share Posted November 28, 2008 I have a list with 1000 tips and I want to show only 10 lines at a time. As I don't want to show the same 10 lines, I shuffle the list. But my code is not working <?php $file = file_get_contents('tips.txt'); $data = explode("",$file); shuffle($data); $newfile = implode("",$data); echo implode("",array_slice(file("$newfile"),0,10)); ?> Link to comment https://forums.phpfreaks.com/topic/134685-solved-why-doesnt-this-code-work/ Share on other sites More sharing options...
Mark Baker Posted November 28, 2008 Share Posted November 28, 2008 Simplify things by reading the file directly into an array $data = file('tips.txt'); Link to comment https://forums.phpfreaks.com/topic/134685-solved-why-doesnt-this-code-work/#findComment-701316 Share on other sites More sharing options...
Mchl Posted November 28, 2008 Share Posted November 28, 2008 What do you expect this to do? $data = explode("",$file); Link to comment https://forums.phpfreaks.com/topic/134685-solved-why-doesnt-this-code-work/#findComment-701326 Share on other sites More sharing options...
nicob Posted November 28, 2008 Author Share Posted November 28, 2008 @Mchl I was using that code to split strings, but I have removed this in my new code. @Mark I made this. It shows 10 lines, BUT shuffle is not working. Maybe now I'm going the wrong direction... <?php $file = file('tips.txt'); shuffle($file); echo implode("",array_slice(file('tips.txt'),-10,10)); ?> Link to comment https://forums.phpfreaks.com/topic/134685-solved-why-doesnt-this-code-work/#findComment-701339 Share on other sites More sharing options...
wildteen88 Posted November 28, 2008 Share Posted November 28, 2008 echo implode("",array_slice(file('tips.txt'),-10,10)); Should be echo implode("",array_slice($file, -10,10)); Link to comment https://forums.phpfreaks.com/topic/134685-solved-why-doesnt-this-code-work/#findComment-701347 Share on other sites More sharing options...
nicob Posted November 28, 2008 Author Share Posted November 28, 2008 You did it again, Wildteen thx everybody Link to comment https://forums.phpfreaks.com/topic/134685-solved-why-doesnt-this-code-work/#findComment-701354 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.