display problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yang Li Ke

    display problem

    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($arrTe xt); $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


  • Cameron

    #2
    Re: display problem

    Yang Li Ke wrote:[color=blue]
    > 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($arrTe xt); $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?
    >[/color]

    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

    Comment

    • Shawn Wilson

      #3
      Re: display problem

      Yang Li Ke wrote:[color=blue]
      >
      > 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($arrTe xt); $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[/color]

      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
      shawn@glassgian t.com

      Comment

      • Yang Li Ke

        #4
        Re: display problem

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

        while($line = mysql_fetch_obj ect(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" <foo@bar.invali d> wrote in message
        news:bvu15t$bak $1@news5.svr.po l.co.uk...[color=blue]
        > Yang Li Ke wrote:[color=green]
        > > I have this script which checks multiple domains for a link back to my[/color][/color]
        site:[color=blue][color=green]
        > >
        > > function backlinkCheck($ siteurl, $recip) {
        > > $arrText = @file($siteurl) ;
        > > for ($i=0; $i<count($arrTe xt); $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[/color][/color]
        the[color=blue][color=green]
        > > whole list.
        > > Id like it to display each site after they are done. Anyone can tell me[/color][/color]
        how[color=blue][color=green]
        > > to do this?
        > >[/color]
        >
        > 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[/color]


        Comment

        • Shawn Wilson

          #5
          Re: display problem

          Yang Li Ke wrote:[color=blue]
          >
          > ok but in my main page I call this function like this
          >
          > while($line = mysql_fetch_obj ect(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 ![/color]

          You should probably have a "$" on db_list_of_site s. 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_obj ect($db_list_of _sites)){
          echo backlinkCheck($ line->url, $mysite->url);
          }

          Regards,
          Shawn
          --
          Shawn Wilson
          shawn@glassgian t.com

          Comment

          • Josh Lopez

            #6
            Re: display problem

            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);
            }

            Comment

            • Yang Li Ke

              #7
              Re: display problem

              Thanx a lot!

              Thats exactly what i was looking for!



              --


              "Josh Lopez" <josh.lopez@cox .net> wrote in message
              news:1df4c829.0 402051549.45e43 6f9@posting.goo gle.com...[color=blue]
              > 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);
              > }[/color]


              Comment

              Working...