ted_chou12 Posted December 20, 2006 Share Posted December 20, 2006 I want to know how you can number the explode() for example, the first explode would be one, second two and third three. It goes on as depedent to how many explode there are. The aim of this is to make editing the specific explode easier, I want to be able to edit or delete the specific explode term. Below is my code, so that you can see how it might work out for me.[code]<?php$diaryarray = file($_SESSION['username'] . '/diaryentries.txt');foreach($diaryarray as $v) { list($subject,$entryicon,$datetime,$content) = explode(":separate;",$v); echo '<br><table width=\"100%\" bgcolor="#ffffff"><tr><td valign=top width="100"><b>Entry Icon:</b></td><td width="600"><img src="smilies/' . $entryicon . '.gif"></td></tr><tr><td valign=top><font face="arial" size=4><b>Subject: </b></font></td><td><font face="arial" size=4><b>' . $subject . '</b></font></td></tr><tr><td valign=top><font face="arial" size=4><b>Posted on:</b></font></td><td valign=top><font face="arial" size=4><b>' . $datetime . '</b></font></td></tr><tr><td valign=top><font face="arial" size=4><b>Entry Content:</b></font></td><td><font face="arial" size=4>' . $content . '</font></td></tr></table>' . "\r\n";}?>[/code]Thanks Ted. Link to comment https://forums.phpfreaks.com/topic/31336-how-do-you-number-the-explode/ Share on other sites More sharing options...
chronister Posted December 20, 2006 Share Posted December 20, 2006 explode() creates an array so by default you can access them using numbers starting at 0[code]$string='this.is.a.string';$strings=explode('.',$string);echo $strings[0].'<br>';echo $strings[1].'<br>';echo $strings[2].'<br>';echo $strings[3].'<br>';[/code]producesthisisastring Link to comment https://forums.phpfreaks.com/topic/31336-how-do-you-number-the-explode/#findComment-145025 Share on other sites More sharing options...
ted_chou12 Posted December 20, 2006 Author Share Posted December 20, 2006 hey, thanks, I understand. :D but instead of numbering each string in the set, for my two level explode, can you number the sets, by that I mean, each $username, $name, ... is a set, so you can echo something like set five username or set10 name.Do you understand what I am talking about??? if not i will explain it to youThanksTed. Link to comment https://forums.phpfreaks.com/topic/31336-how-do-you-number-the-explode/#findComment-145028 Share on other sites More sharing options...
ted_chou12 Posted December 20, 2006 Author Share Posted December 20, 2006 hey, I think by those I mean could you also number the elements in the $diaryentry array? because is taken out as file() so isnt it an array anyways? Link to comment https://forums.phpfreaks.com/topic/31336-how-do-you-number-the-explode/#findComment-145031 Share on other sites More sharing options...
chronister Posted December 20, 2006 Share Posted December 20, 2006 yes the file() method produces an array.[code]$diaryentry[0] // this will produce the first line of the file$diaryentry[1] // this will produce the second line of the file[/code]I hope this helps, if not post an example of what is contained in the txt file so I can see what you are trying to explodenate Link to comment https://forums.phpfreaks.com/topic/31336-how-do-you-number-the-explode/#findComment-145035 Share on other sites More sharing options...
ted_chou12 Posted December 20, 2006 Author Share Posted December 20, 2006 thanks nate, I think it works, I will tell you how the results are after I try them.Ted. Link to comment https://forums.phpfreaks.com/topic/31336-how-do-you-number-the-explode/#findComment-145134 Share on other sites More sharing options...
ted_chou12 Posted December 20, 2006 Author Share Posted December 20, 2006 okay, this is how my txt files roughly looks like:[code]subject1:separate;picture1:separate;time1:separate;content1subject2:separate;picture2:separate;time2:separate;content2subject3:separate;picture3:separate;[color=red]time3[/color]:separate;content3subject4:separate;picture4:separate;time4:separate;content4subject5:separate;picture5:separate;time5:separate;content5[/code]where ":separate;" is what I use to divide my data into pieces, what I wish to know is how do you call a specific data piece, such as I want the time of data set 3 (which is colored in red), or anyother else?do i need to put this "$strings[2]:separate;'<br>';" and this "$diaryarray[3];" together? if so, how do I put them together?Thanks, Ted. Link to comment https://forums.phpfreaks.com/topic/31336-how-do-you-number-the-explode/#findComment-145154 Share on other sites More sharing options...
Orio Posted December 20, 2006 Share Posted December 20, 2006 [code]<?php//set $filename to the filename the data is infunction explode_lines ($filename){ $lines = file($filename); foreach($lines as $num => $line) $lines[$num] = explode(":separate;", $line); return $lines;}$data = explode_lines("filename.txt");echo $data[0][0]; //will echo the subject in the first lineecho $data[4][3]; //will echo the content of line 5echo $data[12][1]; //will echo the picture of line 13?>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/31336-how-do-you-number-the-explode/#findComment-145158 Share on other sites More sharing options...
ted_chou12 Posted December 20, 2006 Author Share Posted December 20, 2006 thanks Link to comment https://forums.phpfreaks.com/topic/31336-how-do-you-number-the-explode/#findComment-145162 Share on other sites More sharing options...
ted_chou12 Posted December 23, 2006 Author Share Posted December 23, 2006 I wish to combine this:[code]<?php$files = explode("|",$_GET['id']);foreach ($files as $include)include ($include.".html");?>[/code]so that you can have a unique url for each piece of data in a text file.For example, if I have "page.php?id=6" I will have a page including the 6th line of the text file, can anyone help me to do that please?Thanks Ted. Link to comment https://forums.phpfreaks.com/topic/31336-how-do-you-number-the-explode/#findComment-146992 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.