36 users online (2 members and 34 guests)  


  Results 1 to 4 of 4

Related

  1. Replies: 8
  2. Parse HTML    Forum: PHP Forum
    Replies: 4
  3. Help: Double Or Triple Space Lines    Forum: HTML Forum
    Replies: 2
  1. #1
    blink's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    19

    How to parse lines of a reponse?

    Hello,

    I am obtaining HTML source code as a http response into a $response variable.

    How can I go through the response content line by line and print out only the lines containing a certain phrase, for examle "id="?

    Thank for your help in advance.

  2. #2
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382
    you could just do it my way, and put all the lines into an array, then scan every array element and pick the ones you want...
    Code:
    @aryresponse = split("\n", $response);
    for ($i = 0; $i <= $#aryresponse; $i=$i+1){
        $aryresponse[$i] =~ s/\r//g;
        if($aryresponse[$i] =~ /id\=/){
            print "$aryresponse[$i]\n";
        }
    }
    @aryresponse = ();
    the reason i put the line:

    $aryresponse[$i] =~ s/\r//g;

    is because sometimes the chr(10) (one of the next line characters) are left behind. you dont actually need that, but i would use it

  3. #3
    blink's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    19
    Thanks for your help!

  4. #4
    ALL's Avatar
    Super Dooper Nerd

    Status
    Offline
    Join Date
    Feb 2005
    Location
    localhost
    Posts
    382
    no problem



Tags for this Thread