Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

time out ? repost of text formatting

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




Report this thread to moderator Post Follow-up to this message
Old Post
Joker7
04-12-05 08:55 PM


Re: time out ? repost of text formatting
"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
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Kimmo Laine
04-12-05 08:55 PM


Re: time out ? repost of text formatting
"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
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Kimmo Laine
04-15-05 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:07 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.