Home > Archive > PHP Language > April 2005 > time out ? repost of text formatting
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
time out ? repost of text formatting
|
|
| Joker7 2005-04-12, 3:55 pm |
|
Hi One and all,
Having a bit of a problem with text formatting in
the code below I hope some one can tell / show me
where I'm going wrong.
Code 1 works ok, but as the server is down some
times it makes the page hang.So I'm trying to
put a time out i.e. will try for X seconds and
give up load the page with out.Which is where
code2 comings in,it seems to work but the text
formating is all over the place.
I can't see where I have gone wrong,but then I
wouldn't if I fell over it.
Where have I gone wrong!
Thanks
Chris
Code1 http://molehole.info/test/code1.php
<?php
// Get data from audioscrobbler
$file =
@file("http://ws.audioscrobbler.com/txt/recent/jok
er7");
// Check if file was readable
if ($file === false)
{
echo "<p>I could not read file</p>\n";
}
else
{
// Remove empty entry at beginning
array_shift($file);
// Create an empty track array
$tracks = array();
// Get title and date from file, put them in track
array
// also, remove the linebreak at the end of each
entry
for ($i = 0, $x = count($file); $i < $x; $i+=2)
{
$track['title'] = rtrim($file[$i]);
$track['date'] = rtrim($file[$i+1]);
array_push($tracks, $track);
}
// Now that we've got the tracks in the $tracks
array,
// print a simple list of tracks
echo "\n";
foreach ($tracks as $track)
{
printf("\t<font face=Verdana size=1
color=#6699CC><b>\n\t\t%s</b></font><br><font
face=Times New Roman size=1
color=#72609F><i>%s<br>\n\t</i></font>\n",
$track['title'],
$track['date']
);
}
echo "\n";
}
?>
Code2 http://molehole.info/test/code2.php
<?php
// Get data from audioscrobbler
$file = null;
$fp =
@fopen("http://ws.audioscrobbler.com/txt/recent/jo
ker7", "r");
if($fp != null) {
stream_set_timeout($fp, 8);
$data = fread($fp, 100000);
fclose($fp);
$file = explode("n", $data);
}
// Check if file was readable
if ($file == null) {
echo "<p>could not read file</p>n";
}
else {
// Remove empty entry at beginning
array_shift($file);
// Create an empty track array
$tracks = array();
// Get title and date from file, put them in track
array
// also, remove the linebreak at the end of each
entry
for ($i = 0, $x = count($file); $i < $x; $i+=2) {
$track['title'] = trim($file[$i]);
$track['date'] = trim($file[$i+1]);
array_push($tracks, $track);
}
// Now that we've got the tracks in the $tracks
array,
// print a simple list of tracks
echo "n";
foreach ($tracks as $track) {
printf("t<font face=Verdana size=1
color=#6699CC><b>ntt%s</b></font><br><font
face=Times New Roman
size=1 color=#72609F><i>%s<br>nt</i></font>n",
$track['title'],
$track['date']
);
}
echo "n";
}
?>
--
Never argue with an idiot. They will drag you down
to their level,and beat you with experience
| |
| Kimmo Laine 2005-04-12, 3:55 pm |
| "Joker7" <sat_ring@hotmail.com> kirjoitti
viestissä:1113310471. a1a089a8a7b89cf101c019dd80f250a7@teranew
s...
>
>
> Hi One and all,
> Having a bit of a problem with text formatting in
> the code below I hope some one can tell / show me
> where I'm going wrong.
> Code 1 works ok, but as the server is down some
> times it makes the page hang.So I'm trying to
> put a time out i.e. will try for X seconds and
> give up load the page with out.Which is where
> code2 comings in,it seems to work but the text
> formating is all over the place.
> I can't see where I have gone wrong,but then I
> wouldn't if I fell over it.
> Where have I gone wrong!
>
> Thanks
> Chris
>
> Code1 http://molehole.info/test/code1.php
>
> <?php
> // Get data from audioscrobbler
> $file =
> @file("http://ws.audioscrobbler.com/txt/recent/jok
> er7");
>
> // Check if file was readable
> if ($file === false)
> {
> echo "<p>I could not read file</p>\n";
> }
> else
> {
> // Remove empty entry at beginning
> array_shift($file);
>
> // Create an empty track array
> $tracks = array();
>
> // Get title and date from file, put them in track
> array
> // also, remove the linebreak at the end of each
> entry
> for ($i = 0, $x = count($file); $i < $x; $i+=2)
> {
> $track['title'] = rtrim($file[$i]);
> $track['date'] = rtrim($file[$i+1]);
> array_push($tracks, $track);
> }
>
> // Now that we've got the tracks in the $tracks
> array,
> // print a simple list of tracks
> echo "\n";
> foreach ($tracks as $track)
> {
> printf("\t<font face=Verdana size=1
> color=#6699CC><b>\n\t\t%s</b></font><br><font
> face=Times New Roman size=1
> color=#72609F><i>%s<br>\n\t</i></font>\n",
> $track['title'],
> $track['date']
> );
> }
> echo "\n";
> }
> ?>
>
> Code2 http://molehole.info/test/code2.php
>
> <?php
> // Get data from audioscrobbler
> $file = null;
> $fp =
> @fopen("http://ws.audioscrobbler.com/txt/recent/jo
> ker7", "r");
> if($fp != null) {
> stream_set_timeout($fp, 8);
> $data = fread($fp, 100000);
> fclose($fp);
> $file = explode("n", $data);
A wild guess, but is this supposed to be a linebrake \n, not the character
'n'. If it splits text for each letter n, it would explain somewhat why the
data is messed up.
> }
>
> // Check if file was readable
> if ($file == null) {
> echo "<p>could not read file</p>n";
> }
> else {
> // Remove empty entry at beginning
> array_shift($file);
>
> // Create an empty track array
> $tracks = array();
>
> // Get title and date from file, put them in track
> array
> // also, remove the linebreak at the end of each
> entry
> for ($i = 0, $x = count($file); $i < $x; $i+=2) {
> $track['title'] = trim($file[$i]);
> $track['date'] = trim($file[$i+1]);
> array_push($tracks, $track);
> }
>
> // Now that we've got the tracks in the $tracks
> array,
> // print a simple list of tracks
> echo "n";
> foreach ($tracks as $track) {
> printf("t<font face=Verdana size=1
> color=#6699CC><b>ntt%s</b></font><br><font
> face=Times New Roman
> size=1 color=#72609F><i>%s<br>nt</i></font>n",
> $track['title'],
> $track['date']
> );
> }
> echo "n";
> }
> ?>
>
>
> --
> Never argue with an idiot. They will drag you down
> to their level,and beat you with experience
>
>
>
| |
| Kimmo Laine 2005-04-15, 8:55 am |
| "Joker7" <sat_ring@hotmail.com> kirjoitti
viestissä:1113310471. a1a089a8a7b89cf101c019dd80f250a7@teranew
s...
>
>
> Hi One and all,
> Having a bit of a problem with text formatting in
> the code below I hope some one can tell / show me
> where I'm going wrong.
> Code 1 works ok, but as the server is down some
> times it makes the page hang.So I'm trying to
> put a time out i.e. will try for X seconds and
> give up load the page with out.Which is where
> code2 comings in,it seems to work but the text
> formating is all over the place.
> I can't see where I have gone wrong,but then I
> wouldn't if I fell over it.
> Where have I gone wrong!
>
> Thanks
> Chris
>
> Code1 http://molehole.info/test/code1.php
>
> <?php
> // Get data from audioscrobbler
> $file =
> @file("http://ws.audioscrobbler.com/txt/recent/jok
> er7");
>
> // Check if file was readable
> if ($file === false)
> {
> echo "<p>I could not read file</p>\n";
> }
> else
> {
> // Remove empty entry at beginning
> array_shift($file);
>
> // Create an empty track array
> $tracks = array();
>
> // Get title and date from file, put them in track
> array
> // also, remove the linebreak at the end of each
> entry
> for ($i = 0, $x = count($file); $i < $x; $i+=2)
> {
> $track['title'] = rtrim($file[$i]);
> $track['date'] = rtrim($file[$i+1]);
> array_push($tracks, $track);
> }
>
> // Now that we've got the tracks in the $tracks
> array,
> // print a simple list of tracks
> echo "\n";
> foreach ($tracks as $track)
> {
> printf("\t<font face=Verdana size=1
> color=#6699CC><b>\n\t\t%s</b></font><br><font
> face=Times New Roman size=1
> color=#72609F><i>%s<br>\n\t</i></font>\n",
> $track['title'],
> $track['date']
> );
> }
> echo "\n";
> }
> ?>
>
> Code2 http://molehole.info/test/code2.php
>
> <?php
> // Get data from audioscrobbler
> $file = null;
> $fp =
> @fopen("http://ws.audioscrobbler.com/txt/recent/jo
> ker7", "r");
> if($fp != null) {
> stream_set_timeout($fp, 8);
> $data = fread($fp, 100000);
> fclose($fp);
> $file = explode("n", $data);
A wild guess, but is this supposed to be a linebrake \n, not the character
'n'. If it splits text for each letter n, it would explain somewhat why the
data is messed up.
> }
>
> // Check if file was readable
> if ($file == null) {
> echo "<p>could not read file</p>n";
> }
> else {
> // Remove empty entry at beginning
> array_shift($file);
>
> // Create an empty track array
> $tracks = array();
>
> // Get title and date from file, put them in track
> array
> // also, remove the linebreak at the end of each
> entry
> for ($i = 0, $x = count($file); $i < $x; $i+=2) {
> $track['title'] = trim($file[$i]);
> $track['date'] = trim($file[$i+1]);
> array_push($tracks, $track);
> }
>
> // Now that we've got the tracks in the $tracks
> array,
> // print a simple list of tracks
> echo "n";
> foreach ($tracks as $track) {
> printf("t<font face=Verdana size=1
> color=#6699CC><b>ntt%s</b></font><br><font
> face=Times New Roman
> size=1 color=#72609F><i>%s<br>nt</i></font>n",
> $track['title'],
> $track['date']
> );
> }
> echo "n";
> }
> ?>
>
>
> --
> Never argue with an idiot. They will drag you down
> to their level,and beat you with experience
>
>
>
|
|
|
|
|