Author |
Message |
gollum65
New Member


Joined: Jan 24, 2005
Posts: 7
|
Posted:
Tue Jan 25, 2005 6:17 pm |
|
Can someone please give me some guidance. I'm barely versed in php and I'm brand new to nuke.
I have a php script that was sent to me. I'd like to make a block out of the script, but I don't know how and I can't find anything that seems to work.
Below is the code snipet I'm trying to make a block out of. Please note the code you see on lines 3 and 9 are generic variables as the real ones refer to a site that isn't mine. Here's the code:
Code:
<?php
$num = 0;
$fp = fopen("http://www.some_url.com/some-data.txt", "r");
print '<table class="peopleOnline">';
while (!feof($fp))
{
$line = fgets($fp, 999);
if
(preg_match('/^(VARIABLE|VARIABLE|VARIABLE)/', $line))
{
list($position, $cid, $name) = split(":", $line, 6);
print '<tr>';
print '<td><b>' . $position . '</b></td>';
print '<td>' . $name . '</td></tr>';
$num = $num+1;
}
}
print '</table>';
print $num . ' people online';
?>
|
Thanks a TON in advance!
Paul B |
|
|
|
 |
sixonetonoffun
Spouse Contemplates Divorce

Joined: Jan 02, 2003
Posts: 2496
|
Posted:
Tue Jan 25, 2005 6:27 pm |
|
Try something like this.
Change block-Blockfilesname.php to the actual block files name.
Code:
<?php
if (stristr("block-Blockfilesname.php", $_SERVER['SCRIPT_NAME'])) { Header("Location: index.php"); }
$content="";
$num = 0;
$fp = fopen("http://www.some_url.com/some-data.txt", "r");
$content ."<table class="peopleOnline">"
while (!feof($fp))
{
$line = fgets($fp, 999);
if
(preg_match('/^(VARIABLE|VARIABLE|VARIABLE)/', $line))
{
list($position, $cid, $name) = split(":", $line, 6);
$content ."<tr>"
$content ."<td><b>' . $position . '</b></td>"
$content ."<td>' . $name . '</td></tr>"
$num = $num+1;
}
}
$content ."</table>"
$content ."$num . ' people online";
?>
|
|
_________________ [b][size=5]openSUSE 11.4-x86 | Linux 2.6.37.1-1.2desktop i686 | KDE: 4.6.41>=4.7 | XFCE 4.8 | AMD Athlon(tm) XP 3000+ | MSI K7N2 Delta-L | 3GB Black Diamond DDR
| GeForce 6200@433Mhz 512MB | Xorg 1.9.3 | NVIDIA 270.30[/size:2b8 |
|
|
 |
sixonetonoffun

|
Posted:
Tue Jan 25, 2005 6:30 pm |
|
Have to change these variables
' . $position . '
to just
$position
too I didn't notice those until after I posted. |
|
|
|
 |
gollum65

|
Posted:
Tue Jan 25, 2005 6:48 pm |
|
Hrmmm.
I'm probably still not doing it right.
First, I created a block with this code:
Code:
<?php
if (stristr("block-myfilename.php", $_SERVER['SCRIPT_NAME'])) { Header("Location: index.php"); }
$content="";
?>
|
Then I created a file called block-myfilename.php and saved it to my blocks folder with the following:
Code:
<?php
$num = 0;
$fp = fopen("http://www.someurl.com/some-data.txt", "r");
$content ."<table class="peopleOnline">"
while (!feof($fp))
{
$line = fgets($fp, 999);
if
(preg_match('/^(VARIABLE|VARIABLE|VARIABLE)/', $line))
{
list($position, $cid, $name) = split(":", $line, 6);
$content ."<tr>"
$content ."<td><b>$position</b></td>"
$content ."<td>' . $name . '</td></tr>"
$num = $num+1;
}
}
$content ."</table>"
$content ."$num . ' people online";
?>
|
All I get is a blank, empty block when I know it should be outputting data.
If I include the entire contents of sixonetonoffun's reply into the block creation form instead of a .php file, the block shows the actual php code, so I assumed that wasn't correct.
Think I'm getting closer, and thanks sixonetonoffun for the help so far.  |
|
|
|
 |
sixonetonoffun

|
Posted:
Tue Jan 25, 2005 7:11 pm |
|
Try this I made some error before and there was an extra if in your code.
Code:
<?php
if (stristr("block-zabatc.php", $_SERVER['SCRIPT_NAME'])) { Header("Location: index.php"); }
$content="";
$num = 0;
$fp = fopen("http://www./satnet-data.txt", "r");
$content .= "<table class=\"peopleOnline\">\n";
while (!feof($fp))
{
$line = fgets($fp, 999);
if(preg_match('/^(PHX|ABQ|TUS|ELP|AMA|TUS|SDL|ABQ1|PHX1|PRC|IWA|INW|YUM)_[A-Z0-9]*_*(DEL|GND|TWR|APP|DEP|CTR)/', $line))
{
list($position, $cid, $name) = split(":", $line, 6);
$content .= "<tr>\n";
$content .= "<td><b>$position</b></td>\n";
$content .= "<td>$name</td></tr>\n";
$num = $num+1;
}
}
$content.= "</table>\n";
$content.= "$num people online";
?>
|
|
Last edited by sixonetonoffun on Tue Jan 25, 2005 8:15 pm; edited 1 time in total |
|
|
 |
gollum65

|
Posted:
Tue Jan 25, 2005 7:32 pm |
|
You da man sixonetonoffun!
Now I understand it. I just created a block-filename.php, saved it in my blocks folder, then called it in the dropdown menu in the blocks admin menu.
Great job, and thanks again!
Ooops. So much for keeping those site variables private. Can someone at least edit the line: that has "http://www...." in his post so the url isn't showing. Again, that isn't my site is the only reason I'm concerned.
Anywho, I'm starting to like Nuke now.  |
|
|
|
 |
|