GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   PHP code help needed. (https://gfy.com/showthread.php?t=626326)

acctman 06-26-2006 03:48 PM

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 06-26-2006 04:12 PM

use regexp not some gay strpos setup you have...

acctman 06-26-2006 04:55 PM

Quote:

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?

mfps 06-26-2006 04:59 PM

http://us3.php.net/xml

mrkris 06-26-2006 05:00 PM

Quote:

Originally Posted by mfps

If all the data isn't XML he's gonna have a hell of a time :winkwink:

mrkris 06-26-2006 05:02 PM

Quote:

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

acctman 06-26-2006 05:02 PM

its not all xml =/

mfps 06-26-2006 05:03 PM

ahhh theres a function for just about everything :winkwink:

fallenmuffin 06-26-2006 05:04 PM

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

acctman 06-26-2006 05:18 PM

Quote:

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

mrkris 06-26-2006 05:24 PM

Quote:

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.

acctman 06-26-2006 11:03 PM

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


J.P. 06-26-2006 11:21 PM

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...

acctman 06-26-2006 11:38 PM

thank you =)


All times are GMT -7. The time now is 02:00 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123