chwebdesigns Posted June 4, 2007 Share Posted June 4, 2007 Hi, Is there a way to get the PHP code to read a line from the table and write it in a box? What I have is an events table with two columns, Date of Event & Name of Event. This is saved on a page called events.html (can be changed to .php) What I wan is on index.php I want a next event box. So what I want for it is to read from the events page, and find when the next event is, using information on dates. I have no idea on how to start this at all. If you require any other information then just ask From Cal PS ~ I'm a novice at PHP Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/ Share on other sites More sharing options...
chigley Posted June 4, 2007 Share Posted June 4, 2007 <?php function textbetweenarray($s1,$s2,$s){ $myarray=array(); $s1=strtolower($s1); $s2=strtolower($s2); $L1=strlen($s1); $L2=strlen($s2); $scheck=strtolower($s); do{ $pos1 = strpos($scheck,$s1); if($pos1!==false){ $pos2 = strpos(substr($scheck,$pos1+$L1),$s2); if($pos2!==false){ $myarray[]=substr($s,$pos1+$L1,$pos2); $s=substr($s,$pos1+$L1+$pos2+$L2); $scheck=strtolower($s); } } } while (($pos1!==false)and($pos2!==false)); return $myarray; } $content = file_get_contents("events.html"); $table = textbetweenarray("<table>", "</table>", $content); $table = $table[0]; $tds = textbetweenarray("<td>", "</td>", $table); $date = $tds[0]; $name = $tds[1]; echo "Next event: {$name} on {$date}!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267758 Share on other sites More sharing options...
chwebdesigns Posted June 4, 2007 Author Share Posted June 4, 2007 That works for the Event but it doesn't work for the date. Here is the code for my table: <table width="567" border="1" align="center" cellpadding="0" cellspacing="0" id="events"> <tr bgcolor="#FF9933"> <td colspan="2"><div align="center"> <p><strong>JUNE</strong></p> </div></td> </tr> <tr> <td width="120"><div align="center"> <p>Sun 3rd June </p> </div></td> <td width="441"><div align="center"> <p>Int. Comp</p> </div></td> </tr> <tr> <td width="120"><div align="center"> <p>Sat 9th June </p> </div></td> <td><div align="center"> <p>Class 3 Judges Course</p> </div></td> </tr> <tr> <td width="120"><div align="center"> <p>Sun 10th June </p> </div></td> <td><div align="center"> <p>Comp</p> </div></td> </tr> <tr> <td width="120"><div align="center"> <p>Sun 24th June </p> </div></td> <td><div align="center"> <p>First Aid Course</p> </div></td> </tr> <tr bgcolor="#FF9933"> <td colspan="2"><div align="center"> <p><strong>JULY</strong></p> </div></td> </tr> <tr> <td width="120"><div align="center"> <p>Sun 1st July 07 </p> </div></td> <td><div align="center"> <p>Comp </p> </div></td> </tr> <tr> <td width="120"><div align="center"> <p>Sat 7th & <br> Sun 8th July </p> </div></td> <td><div align="center"> <p>Seminar 321</p> </div></td> </tr> <tr> <td width="120"><div align="center"> <p>Sun 15th July </p> </div></td> <td><div align="center"> <p>Grading 8 </p> </div></td> </tr> <tr> <td width="120"><div align="center"> <p>Sun 22nd July </p> </div></td> <td><div align="center"> <p>Competition 198</p> </div></td> </tr> </table> Thanks for your help from cal Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267771 Share on other sites More sharing options...
chigley Posted June 4, 2007 Share Posted June 4, 2007 <?php function textbetweenarray($s1,$s2,$s){ $myarray=array(); $s1=strtolower($s1); $s2=strtolower($s2); $L1=strlen($s1); $L2=strlen($s2); $scheck=strtolower($s); do{ $pos1 = strpos($scheck,$s1); if($pos1!==false){ $pos2 = strpos(substr($scheck,$pos1+$L1),$s2); if($pos2!==false){ $myarray[]=substr($s,$pos1+$L1,$pos2); $s=substr($s,$pos1+$L1+$pos2+$L2); $scheck=strtolower($s); } } } while (($pos1!==false)and($pos2!==false)); return $myarray; } $content = file_get_contents("events.html"); $table = textbetweenarray("<table width=\"567\" border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" id=\"events\">", "</table>", $content); $table = $table[0]; $tr = textbetweenarray("<tr>", "</tr>", $table); $tr = $tr[0]; $data = textbetweenarray("<p>", "</p>", $tr); $name = $data[0]; $date = $data[1]; echo "Next event: {$name} on {$date}!"; ?> Try that? Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267773 Share on other sites More sharing options...
chwebdesigns Posted June 4, 2007 Author Share Posted June 4, 2007 Yes thank you, the date and competition info work fine now. Is there a way of getting it to update automatically to the date? For e.g. : The top event on the calendar at the moment is Sun 3rd June, which was yesterday, could it automatically show the next event? Thanks very much from cal Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267777 Share on other sites More sharing options...
chigley Posted June 4, 2007 Share Posted June 4, 2007 Yes that code will look at the first row after from the coloured one saying the month name, so it is automatically updating to the latest event Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267785 Share on other sites More sharing options...
chwebdesigns Posted June 4, 2007 Author Share Posted June 4, 2007 Oh yes :S Thank you very much for that, it's just what I needed. Cheers from Cal Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267788 Share on other sites More sharing options...
chwebdesigns Posted June 4, 2007 Author Share Posted June 4, 2007 Is there a way of changing the "Sunday 3rd June" to >> 03/06/07 and the same for all of the other dates. ??? cheers from cal Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267800 Share on other sites More sharing options...
chigley Posted June 4, 2007 Share Posted June 4, 2007 You can try this.. : <?php function textbetweenarray($s1,$s2,$s){ $myarray=array(); $s1=strtolower($s1); $s2=strtolower($s2); $L1=strlen($s1); $L2=strlen($s2); $scheck=strtolower($s); do{ $pos1 = strpos($scheck,$s1); if($pos1!==false){ $pos2 = strpos(substr($scheck,$pos1+$L1),$s2); if($pos2!==false){ $myarray[]=substr($s,$pos1+$L1,$pos2); $s=substr($s,$pos1+$L1+$pos2+$L2); $scheck=strtolower($s); } } } while (($pos1!==false)and($pos2!==false)); return $myarray; } $content = file_get_contents("events.html"); $table = textbetweenarray("<table width=\"567\" border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" id=\"events\">", "</table>", $content); $table = $table[0]; $tr = textbetweenarray("<tr>", "</tr>", $table); $tr = $tr[0]; $data = textbetweenarray("<p>", "</p>", $tr); $name = $data[0]; $date = $data[1]; $timestamp = strtotime($date); $output = date("D/M/Y", $timestamp); echo "Next event: {$name} on {$output}!"; ?> Not sure if that'll work though.. Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267809 Share on other sites More sharing options...
chwebdesigns Posted June 4, 2007 Author Share Posted June 4, 2007 No unfortunately it doesnt, it comes out as Sun/Jun/2007 , do I need to use an if statement? Thanks from cal Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267818 Share on other sites More sharing options...
chigley Posted June 4, 2007 Share Posted June 4, 2007 $timestamp = strtotime($date); $output = date("d/m/y", $timestamp); My bad, use that. Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267821 Share on other sites More sharing options...
chwebdesigns Posted June 4, 2007 Author Share Posted June 4, 2007 Thanks for that, just what I needed, From Cal Quote Link to comment https://forums.phpfreaks.com/topic/54161-solved-php-events-box/#findComment-267839 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.