||09-25-2007 07:57 PM
Reading from txt file..
Hello.. This is my first question and just want to say before it that this is awesome forum!! Thanks for that..
Ok.. I need to read text file and every second line ONLY!?
and so on..
I have here my script which will print all lines. If someone could look at it and maybe quide me how to modify this so it will print only every second line like I sayd before.
$filename = "postitoimi.txt";
$file = fopen($filename,"r");
$print = file("postitoimi.txt");
$lines = count($print);
$lines2 = $lines - 1;
$i = 0;
while ($i <= $lines2)
$patterns = array("(","'",")",",");
$replacements = array("","",""," ");
$data = str_replace($patterns, $replacements, $print[$i]);
$data = explode(",", $data);
print($data . $data . "<br />");
Reason why I need to do this is that, in that textfile there is 2 information for every one ID number. And those are all inviditual lines. My customers old CMS is doing that now I need to convert that into my own CMS..
anyway, thanks for all help!
||09-25-2007 08:11 PM
This code gives you a basic idea of how to do this. We loop through the lines in the file and issue the
construct to any lines that are odd. So it begins at line 1, skips line 2, prints line 3, etcetera...
Glad you like it here as well :) !
$aContents = file('file.txt');
for($iIndex = 0; $iIndex < count($aContents); $iIndex++)
if($iIndex % 2 == 1)
echo $aContents[$iIndex] . '<br />';
||09-25-2007 08:20 PM
wow.. Thanks for faaaast reply!
Well, yeah.. I think I can go from here. It looks actually really simple..
Thank you Wildhoney.
||09-25-2007 08:29 PM
Haha, that looked really simple wild~ :D
|All times are GMT. The time now is 07:16 PM.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0