PHP code help needed.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acctman
    Confirmed User
    • Oct 2003
    • 2840

    #1

    PHP code help needed.

    Hi i'm stuck on where to add my Do While Loop statement ... below is the section of the coding that is being processed. what is happening is the source is examined and the version codes are grabbed. but, it needs to loop through the source and grab all version codes and not just the first one.

    thanks in advance

    Code:
                    $resp = curl_exec($ch); 
                    //echo "$resp\n"; 
                    curl_close($ch);       
                    $startkey = "<024version>"; 
                    $stopkey = "</024version>";         
                    $startpos = strpos($resp, $startkey);  
                    if ($startpos !hahahaha false) {  
                        $startpos += strlen($startkey);  
                        $endpos = strpos($resp, $stopkey, $startpos); 
                        $len = ($endpos - $startpos);  
                        $writecontent .= substr($resp, $startpos, $len)."\n";  
                        echo "$writecontent\n"; 
         
                    } 
    $fp = fopen($outputfile,"w"); 
    fwrite($fp,$writecontent); 
    fclose($fp);
  • woj
    <&(©¿©)&>
    • Jul 2002
    • 47882

    #2
    use regexp not some gay strpos setup you have...
    Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
    Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
    Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

    Comment

    • acctman
      Confirmed User
      • Oct 2003
      • 2840

      #3
      Originally posted by woj
      use regexp not some gay strpos setup you have...
      the gay was was the only way i knew... with regexp is it possible to grab the data from in between <024version>Model#</024version>? The examples of regexp usage i'm finding pretty much shows how to replace.

      also back to my original question where should my do loop go?

      Comment

      • mfps
        Confirmed User
        • Mar 2006
        • 640

        #4
        http://us3.php.net/xml

        Comment

        • mrkris
          Confirmed User
          • May 2005
          • 2737

          #5
          Originally posted by mfps
          If all the data isn't XML he's gonna have a hell of a time

          PHP-MySQL-Rails | ICQ: 342500546

          Comment

          • mrkris
            Confirmed User
            • May 2005
            • 2737

            #6
            Originally posted by acctman
            Hi i'm stuck on where to add my Do While Loop statement ... below is the section of the coding that is being processed. what is happening is the source is examined and the version codes are grabbed. but, it needs to loop through the source and grab all version codes and not just the first one.

            thanks in advance

            Code:
                            $resp = curl_exec($ch); 
                            //echo "$resp\n"; 
                            curl_close($ch);       
                            $startkey = "<024version>"; 
                            $stopkey = "</024version>";         
                            $startpos = strpos($resp, $startkey);  
                            if ($startpos !hahahaha false) {  
                                $startpos += strlen($startkey);  
                                $endpos = strpos($resp, $stopkey, $startpos); 
                                $len = ($endpos - $startpos);  
                                $writecontent .= substr($resp, $startpos, $len)."\n";  
                                echo "$writecontent\n"; 
                 
                            } 
            $fp = fopen($outputfile,"w"); 
            fwrite($fp,$writecontent); 
            fclose($fp);
            If it's not all XML, use preg_match_all()
            http://us3.php.net/preg_match_all

            PHP-MySQL-Rails | ICQ: 342500546

            Comment

            • acctman
              Confirmed User
              • Oct 2003
              • 2840

              #7
              its not all xml =/

              Comment

              • mfps
                Confirmed User
                • Mar 2006
                • 640

                #8
                ahhh theres a function for just about everything

                Comment

                • fallenmuffin
                  Confirmed User
                  • Nov 2005
                  • 8170

                  #9
                  Woah, your code just took me back to 1995.. thank ya

                  Comment

                  • acctman
                    Confirmed User
                    • Oct 2003
                    • 2840

                    #10
                    Originally posted by mrkris
                    If it's not all XML, use preg_match_all()
                    http://us3.php.net/preg_match_all
                    something like this would grab all without running a do loop?...
                    Code:
                    preg_match_all('|<024version>(.*?)</024version>|',$resp,$writecontent);
                    hehe fallenmuffin yeah i know my coding sucks... i need update my php reference book
                    Last edited by acctman; 06-26-2006, 04:20 PM.

                    Comment

                    • mrkris
                      Confirmed User
                      • May 2005
                      • 2737

                      #11
                      Originally posted by acctman
                      something like this would grab all without running a do loop?...
                      Code:
                      preg_match_all('|<024version>(.*?)</024version>|',$resp,$writecontent);
                      hehe fallenmuffin yeah i know my coding sucks... i need update my php reference book
                      Yup, one function to search an entire string for multiple matches.

                      PHP-MySQL-Rails | ICQ: 342500546

                      Comment

                      • acctman
                        Confirmed User
                        • Oct 2003
                        • 2840

                        #12
                        ok seems to be working except one issue... damn array.. how do you pull the results from the array... it's listing them one i do a print_r but but will not output them to the. all i'm getting in the file is Array repeated on each line

                        Code:
                        $lookfor ="|<024version>(.*?)</024version>|Ui";	
                        preg_match_all($lookfor,$html,$results);
                        
                        print_r($results[1]); 
                        $writecontent .= "$results[1]\n";
                        
                        echo "$result[1]\n";
                        
                        $fp = fopen($outputfile,"a");
                        fwrite($fp,$writecontent);
                        fclose($fp);

                        Comment

                        • J.P.
                          Confirmed User
                          • Jun 2004
                          • 689

                          #13
                          Code:
                          $lookfor = '|<024version>(.*)</024version>|Ui';
                          preg_match_all($lookfor,$html,$results,PREG_PATTERN_ORDER);
                          
                          $writecontent = '';
                          for ($c = 0; $c < sizeof($results[1]); $c++) {
                              $writecontent .= $results[1][$c]."\n";
                          }
                          
                          $fp = fopen($outputfile,'a');
                          fwrite($fp,$writecontent);
                          fclose($fp);
                          this should do it...
                          Webmasters! Looking for new affiliate programs to promote?
                          Affiliate Program Search <-- Search for programs with FHGs, RSS feed, specific niche sponsors, ...

                          Comment

                          • acctman
                            Confirmed User
                            • Oct 2003
                            • 2840

                            #14
                            thank you =)

                            Comment

                            Working...