function httpPost($ip = null, $port = 80, $uri = null, $content = null) { if (empty($ip)) { return false; } if (!is_numeric($port)) { return false; } if (empty($uri)) { return false; } if (empty($content)) { return false; } // generate headers in array. $t = array(); $t[] = 'POST ' . $uri . ' HTTP/1.1'; $t[] = 'Content-Type: text/html'; $t[] = 'Host: ' . $ip . ':' . $port; $t[] = 'Content-Length: ' . strlen($content); $t[] = 'Connection: close'; $t = implode("\r\n", $t) . "\r\n\r\n" . $content; // // Open socket, provide error report vars and timeout of 10 // seconds. // $fp = @fsockopen($ip, $port, $errno, $errstr, 10); // If we don't have a stream resource, abort. if (!(get_resource_type($fp) == 'stream')) { return false; } // // Send headers and content. // if (!fwrite($fp, $t)) { fclose($fp); return false; } // // Read all of response into $rsp and close the socket. // $rsp = ''; while (!feof($fp)) { $rsp .= fgets($fp, 8192); } fclose($fp); // // Call parseHttpResponse() to return the results. // return parseHttpResponse($rsp); }
//Given: http://github.com/bluescripts/bbug/commits/master //Need: http://github.com/api/v1/xml/bluescripts/bbug/commits/master $fp = fsockopen("github.com", 80, $errno, $errstr, 30); if (!$fp) { echo "{$errstr} ({$errno})<br />\n"; } else { $out = "GET /api/v1/xml/" . $user_proj . "/commit/" . $sum . " HTTP/1.1\r\n"; $out .= "Host: google.com \r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { $results .= fgets($fp, 128); } fclose($fp); } $post_results = parseHttpResponse($results); $objXML = new xml2Array(); $arrOutput = $objXML->parse($post_results); $g = $arrOutput[0]['children'][3]['children']; for ($i = 0; $i < count($g); $i++) { $file = $g[$i]['children'][1]['tagData']; $diff = $g[$i]['children'][0]['tagData']; $diff = str_replace('>', '>', str_replace('<', '<', $diff)); # do highlighting $diff = preg_replace('/\\+(.*)/', '<span id="add">$1</span>', $diff); $diff = preg_replace('/\\-(.*)/', '<span id="remove">$1</span>', $diff); echo "<div id='file'>{$file}</div>"; echo "<div id='diff'>" . nl2br($diff) . "</div><hr>"; } //$arrOuptut = array_map() //$diff = $arrOutput[]