Loading ...
Sorry, an error occurred while loading the content.

Re: [bang-phpug] PHP While Loop Question, please answer

Expand Messages
  • Koushik G raj
    Hi Trinadh, try this. while(($a[$i] !=
    Message 1 of 7 , Dec 28, 2008
    • 0 Attachment
      Hi Trinadh,

      try this.
      while(($a[$i] !="<" || $a[$i+1]!="a") && $i<$l)

      --- On Sun, 28/12/08, thisistrinath <thisistrinath@...> wrote:
      From: thisistrinath <thisistrinath@...>
      Subject: [bang-phpug] PHP While Loop Question, please answer
      To: bang-phpug@yahoogroups.com
      Date: Sunday, 28 December, 2008, 12:08 PM











      Hello,

      It seems odd to ask a question on while loop but the problem

      itself is equally odd.

      $a="<html><head> </head><body> <a href=";//a string

      $l=strlen($a) ;

      $i=0;

      while($a[$i] !="<" && $a[$i+1]!="a" && $i<$l){$i++; }

      echo $i;

      A simple thing as this should give me the output 25, whereas it is

      giving me 9. Please tell me where is the problem or is that the PHP

      while loop cannot check more than two conditions at a time(as here are 3).

      Thank you

      -Trinadh



























      Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/

      [Non-text portions of this message have been removed]
    • janakiraman
      Hi thisistrinath, Otherwise use like this and check it out..
      Message 2 of 7 , Dec 29, 2008
      • 0 Attachment
        Hi thisistrinath,
        Otherwise use like this and check it out..
        <?php

        $a="<html><head></head><body><a href=";//a string
        $l=strlen($a) ;
        $i=0;
        while($i<$l){
        if($a[$i] =="<" && $a[$i+1]=="a" && $i<$l)
        break;
        $i++;
        }
        echo $i;
        ?>

        Thanks

        B. Janakiraman

        --- On Mon, 29/12/08, Udayakumar Sarangapani <udayakumar.sarangapani@...> wrote:
        From: Udayakumar Sarangapani <udayakumar.sarangapani@...>
        Subject: Re: [bang-phpug] PHP While Loop Question, please answer
        To: bang-phpug@yahoogroups.com
        Date: Monday, 29 December, 2008, 1:03 PM











        Hi Srikanth,



        When i debugged and ran your code, i got 0 as the output. I don't know the

        reason.



        why don't you change the logic as follows?



        <?php

        $a="<html><head> </head><body> <a href=";//a string

        $l=strlen($a) ;

        $j = -1;



        for($i=0; $i < $l; $i++) {

        if ($a[$i] == "<" && $a[$i+1] == "a") {

        $j = $i;

        }

        }



        if ($j != -1) {

        echo $j;

        }

        ?>



        On Sun, Dec 28, 2008 at 12:08 PM, thisistrinath

        <thisistrinath@ yahoo.co. in>wrote:



        > Hello,

        > It seems odd to ask a question on while loop but the problem

        > itself is equally odd.

        > $a="<html><head> </head><body> <a href=";//a string

        > $l=strlen($a) ;

        > $i=0;

        > while($a[$i] !="<" && $a[$i+1]!="a" && $i<$l){$i++; }

        > echo $i;

        > A simple thing as this should give me the output 25, whereas it is

        > giving me 9. Please tell me where is the problem or is that the PHP

        > while loop cannot check more than two conditions at a time(as here are 3)..

        > Thank you

        > -Trinadh

        >

        >

        >



        [Non-text portions of this message have been removed]



























        Connect with friends all over the world. Get Yahoo! India Messenger at http://in.messenger.yahoo.com/?wm=n/

        [Non-text portions of this message have been removed]
      • thisistrinath
        Hello friends, Thank you for replying me, I was trying to build a URL extractor. But since I couldn t get the while loop right I moved to for and if loop
        Message 3 of 7 , Dec 30, 2008
        • 0 Attachment
          Hello friends, Thank you for replying me, I was trying to build a URL
          extractor. But since I couldn't get the while loop right I moved to
          for and if loop system. I will finish the code and show to you people
          so you can run and see.
          Thank you
          Trinadh Yerra
        Your message has been successfully submitted and would be delivered to recipients shortly.