display problem – PHP

  php

Q(Question):

I have this script which checks multiple domains for a link back to my site:

function backlinkCheck($siteurl, $recip) {
$arrText = @file($siteurl);
for ($i=0; $i<count($arrText); $i++) {
$text = $text . $arrText[$i];
}
if (eregi($recip, $text)) {
return true;
} else {
return false;
}
}

The problem is that It displays true or false only after it went through the
whole list.
Id like it to display each site after they are done. Anyone can tell me how
to do this?


Yang

A(Answer):

Yang Li Ke wrote:

I have this script which checks multiple domains for a link back to my site:

function backlinkCheck($siteurl, $recip) {
$arrText = @file($siteurl);
for ($i=0; $i<count($arrText); $i++) {
$text = $text . $arrText[$i];
}
if (eregi($recip, $text)) {
return true;
} else {
return false;
}
}

The problem is that It displays true or false only after it went through the
whole list.
Id like it to display each site after they are done. Anyone can tell me how
to do this?

Calling return stops the function and gives control back to the calling
function or script and the loop would stop so no you couldn’t for
example return on one then carry on itterating through the list.

~Cameron

A(Answer):

Yang Li Ke wrote:

I have this script which checks multiple domains for a link back to my site:

function backlinkCheck($siteurl, $recip) {
$arrText = @file($siteurl);
for ($i=0; $i<count($arrText); $i++) {
$text = $text . $arrText[$i];
}
if (eregi($recip, $text)) {
return true;
} else {
return false;
}
}

The problem is that It displays true or false only after it went through the
whole list.
Id like it to display each site after they are done. Anyone can tell me how
to do this?


Yang

This should work as long as $recip will always be on one line, which should be
the case if you’re just looking for your domain.

function backlinkCheck($siteurl, $recip) {
$arrText = @file($siteurl);
foreach ($arrText as $text) {
if (eregi($recip, $text))
return true;
}
return false;
}

You also might want to look up foreach, join(), and the ".=" operator for the
future. They aren’t needed here any more, but could have made your code a bit
more efficient/readable. You might also want to add some error handling (try
entering a bogus url and see what happens).

Regards,
Shawn

Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

A(Answer):

ok but in my main page I call this function like this

while($line = mysql_fetch_object(db_list_of_sites)){
echo backlinkCheck($line->url, $mysite->url);
}

so the problem is that it doesnt echo the result after each
site. it echo the results only at end when the whole while
is done !

Thanx for you help.

Yang

"Cameron" <fo*@bar.invalid> wrote in message
news:bv**********@news5.svr.pol.co.uk…

Yang Li Ke wrote:

I have this script which checks multiple domains for a link back to my
site:
function backlinkCheck($siteurl, $recip) {
$arrText = @file($siteurl);
for ($i=0; $i<count($arrText); $i++) {
$text = $text . $arrText[$i];
}
if (eregi($recip, $text)) {
return true;
} else {
return false;
}
}

The problem is that It displays true or false only after it went through
the whole list.
Id like it to display each site after they are done. Anyone can tell me
how to do this?

Calling return stops the function and gives control back to the calling
function or script and the loop would stop so no you couldn’t for
example return on one then carry on itterating through the list.

~Cameron

A(Answer):

Yang Li Ke wrote:

ok but in my main page I call this function like this

while($line = mysql_fetch_object(db_list_of_sites)){
echo backlinkCheck($line->url, $mysite->url);
}

so the problem is that it doesnt echo the result after each
site. it echo the results only at end when the whole while
is done !

You should probably have a "$" on db_list_of_sites. This should have produced
an error – I’d suggest turning on error_reporting() if you didn’t see it. It
can really help to debug.
while($line = mysql_fetch_object($db_list_of_sites)){
echo backlinkCheck($line->url, $mysite->url);
}

Regards,
Shawn

Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com

A(Answer):

You need to ‘flush’ the output to the browser after each iteration,
check out the following example for some ideas. The usleep call is
there so that you have enough of a delay between each ‘flush’ to see
the example work.
for( $i=0; $i<100; $i++ ) {
echo $i;
flush();
ob_flush();
usleep(50000);
}

A(Answer):

Thanx a lot!

Thats exactly what i was looking for!


"Josh Lopez" <jo********@cox.net> wrote in message
news:1d**************************@posting.google.c om…

You need to ‘flush’ the output to the browser after each iteration,
check out the following example for some ideas. The usleep call is
there so that you have enough of a delay between each ‘flush’ to see
the example work.
for( $i=0; $i<100; $i++ ) {
echo $i;
flush();
ob_flush();
usleep(50000);
}

LEAVE A COMMENT