OLG Posted July 7, 2007 Share Posted July 7, 2007 Hey, Approximately 2 years ago i asked a question on regular expressions, the topic is therefore archaeic and unrecoverable but contained the info i needed to solve my current problem. <?php $mycookies = GetCookies("www.site.com/login.php", "usrname=user&password=pass&usermail=user@email.com&submit=LOGIN&set=Y",""); $opts = @array('http'=>array('method'=>"GET", 'header'=>"Accept-language: en\r\nCookie: ".$mycookies."\r\n" )); $context = stream_context_create($opts); $fp = fopen('http://www.site.com/statistics.php?id=2111292', 'r', false, $context); fpassthru($fp); $html = fread($fp, 1000000); fclose($fp); $strip = strip_tags($html); echo $strip; function PostPage($host,$query,$others=''){ $path=explode('/',$host); $host=$path[0]; unset($path[0]); $path='/'.(implode('/',$path)); $post="POST $path HTTP/1.1\r\nHost: $host\r\n"; $post.="Content-type: application/x-www-form-"; $post.="urlencoded\r\n${others}"; $post.="User-Agent: Mozilla 4.0\r\nContent-length: "; $post.=strlen($query)."\r\nConnection: close\r\n\r\n$query"; $h=fsockopen($host,80); fwrite($h,$post); for($a=0,$r='';!$a;){ $b=fread($h,8192); $r.=$b; $a=(($b=='')?1:0); } fclose($h); return $r; } function GetCookies($host,$query,$others=''){ $path=explode('/',$host); $host=$path[0]; unset($path[0]); $crlf = "\r\n"; $path='/'.(implode('/',$path)); $post="POST $path HTTP/1.1\r\nHost: $host\r\n"; $post.="Content-type: application/x-www-form-urlencoded\r\n${others}"; $post.="User-Agent: Mozilla 4.0\r\nContent-length: "; $post.=strlen($query)."\r\nConnection: close\r\n\r\n$query"; $h=fsockopen($host,80); fwrite($h,$post); $r=""; for($a=0;!$a;){ $b=fread($h,512); echo $b; $r.=$b; $gotSession=strpos($r,"ASPSESSION"); if($gotSession) if(strpos($r, $crlf . $crlf,$gotSession)>0) break; $a=(($b=='')?1:0); } fclose($h); $arr = split("Set-Cookie:",$r); $AllCookies="";$count=1; while ($count < count($arr)) { $AllCookies.=substr($arr[$count].";", 0,strpos($arr[$count].";",";")+1); $count++;} return $AllCookies; } ?> This is my current script - if i just run down what im doing here. I'm using fsock to establish a connection to a third party site and then submitting a set of details in order to login - i then strip the html tags away from the page that i've fopened and read. What i now need is to use preg_match to extract the string "Rank: 999,999" for example and then split that down to 999,999 and then remove the comma - this is the part i am stuck on - i just really don't understand regular expressions. Does anyone think they could help me out here and then explain it? Thank You Quote Link to comment https://forums.phpfreaks.com/topic/58843-solved-previous-question-regular-expressions/ Share on other sites More sharing options...
bibby Posted July 7, 2007 Share Posted July 7, 2007 Hi OLG. Neat scrape. I'm not so good with RegEx either, but you can probably get what you want with explode() alone. // after you've assign $html $x= explode('Rank: ',$html,2); if($x[1]) $y = explode(' ',$x[1],2); $rank = str_replace(',','',$y[0]); if(is_numeric($rank)) echo $rank; else echo 'this didnt work after all..'; Quote Link to comment https://forums.phpfreaks.com/topic/58843-solved-previous-question-regular-expressions/#findComment-291962 Share on other sites More sharing options...
OLG Posted July 7, 2007 Author Share Posted July 7, 2007 I don't think that worked Additionally - i have now fixed the stripping issue (stupidly used fpassthru - now sorted) - however there is still some javascript in the result - so i need to remove that. I'm fairly certain that it didn't - any other ideas? Thanks for the help so far (that was very fast). Adam Quote Link to comment https://forums.phpfreaks.com/topic/58843-solved-previous-question-regular-expressions/#findComment-291986 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.