This took me some time this morning.
For a secured part of a website I made up a log of both succesfull as failed logins.
I wanted to output the last 20 or so lines, for displaying those on a helpdesk page.

I came up with the following solution and I think it’s a elegant one:
1 <font color="#000000"></font><font color="#0000BB"><?php<br /> <span style="color: black;">2</span> $logbuffer</font> <font color="#007700">= `</font><font color="#0000BB">tail -n 10 /path/to/somelog.log</font><font color="#007700">`;<br /> <span style="color: black;">3</span><br /> <span style="color: black;">4</span></font> <font color="#0000BB">$log_array</font> <font color="#007700">=</font> <font color="#0000BB">explode</font><font color="#007700">(</font><font color="#DD0000">"\n"</font><font color="#007700">,</font> <font color="#0000BB">$logbuffer</font><font color="#007700">);<br /> <span style="color: black;">5</span><br /> <span style="color: black;">6</span> foreach (</font><font color="#0000BB">$log_array</font> <font color="#007700">as</font> <font color="#0000BB">$logline</font><font color="#007700">) {<br /> <span style="color: black;">7</span> &nbsp;&nbsp;&nbsp;&nbsp;if (!</font><font color="#0000BB">$logline</font> <font color="#007700">==</font> <font color="#DD0000">''</font><font color="#007700">) {<br /> <span style="color: black;">8</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (</font><font color="#0000BB">ereg</font><font color="#007700">(</font><font color="#DD0000">'error'</font><font color="#007700">,</font> <font color="#0000BB">$logline</font><font color="#007700">)) {<br /> <span style="color: black;">9</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo</font> <font color="#DD0000">"<span class='error'>"</font><font color="#007700">.</font><font color="#0000BB">$logline</font><font color="#007700">.</font><font color="#DD0000">"</span><hr />"</font><font color="#007700">;<br /> <span style="color: black;">10</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> <span style="color: black;">11</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else {<br /> <span style="color: black;">12</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo</font> <font color="#DD0000">"<span class='ok'>"</font><font color="#007700">.</font><font color="#0000BB">$logline</font><font color="#007700">.</font><font color="#DD0000">"</span><hr />"</font><font color="#007700">;<br /> <span style="color: black;">13</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> <span style="color: black;">14</span> &nbsp;&nbsp;&nbsp;&nbsp;}<br /> <span style="color: black;">15</span> }<br /> <span style="color: black;">16</span></font> <font color="#0000BB">?><br /> <span style="color: black;">17</span></font>