: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if(is_array($this->results))
for($x=0;$x<count($this->results);$x++)
$this->results[$x] = $this->_striptext($this->results[$x]);
$this->results = $this->_striptext($this->results);
/*======================================================================*\
Purpose: grab links from a form submission
Input: $URI where you are submitting from
Output: $this->results an array of the links from the post
\*======================================================================*/
function submitlinks($URI, $formvars="", $formfiles="")
if($this->submit($URI,$formvars, $formfiles))
if($this->lastredirectaddr)
$URI = $this->lastredirectaddr;
if(is_array($this->results))
for($x=0;$x<count($this->results);$x++)
$this->results[$x] = $this->_striplinks($this->results[$x]);
$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
$this->results = $this->_striplinks($this->results);
$this->results = $this->_expandlinks($this->results,$URI);
/*======================================================================*\
Purpose: grab text from a form submission
Input: $URI where you are submitting from
Output: $this->results the text from the web page
\*======================================================================*/
function submittext($URI, $formvars = "", $formfiles = "")
if($this->submit($URI,$formvars, $formfiles))
if($this->lastredirectaddr)
$URI = $this->lastredirectaddr;
if(is_array($this->results))
for($x=0;$x<count($this->results);$x++)
$this->results[$x] = $this->_striptext($this->results[$x]);
$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);
$this->results = $this->_striptext($this->results);
$this->results = $this->_expandlinks($this->results,$URI);
/*======================================================================*\
Function: set_submit_multipart
Purpose: Set the form submission content type to
\*======================================================================*/
function set_submit_multipart()
$this->_submit_type = "multipart/form-data";
/*======================================================================*\
Function: set_submit_normal
Purpose: Set the form submission content type to
application/x-www-form-urlencoded
\*======================================================================*/
function set_submit_normal()
$this->_submit_type = "application/x-www-form-urlencoded";
/*======================================================================*\
\*======================================================================*/
/*======================================================================*\
Purpose: strip the hyperlinks from an html document
Input: $document document to strip.
Output: $match an array of the links
\*======================================================================*/
function _striplinks($document)
preg_match_all("'<\s*a\s.*?href\s*=\s* # find <a href=
([\"\'])? # find single or double quote
(?(1) (.*?)\\1 | ([^\s\>]+)) # if quote found, match up to next matching
# quote, otherwise match up to next space
// catenate the non-empty matches from the conditional subpattern
foreach ( $links[2] as $key => $val )
foreach ( $links[3] as $key => $val )
/*======================================================================*\
Purpose: strip the form elements from an html document
Input: $document document to strip.
Output: $match an array of the links
\*======================================================================*/
function _stripform($document)
preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements);
$match = implode("\r\n",$elements[0]);
/*======================================================================*\
Purpose: strip the text from an html document
Input: $document document to strip.
Output: $text the resulting text
\*======================================================================*/
function _striptext($document)
// I didn't use preg eval (//e) since that is only available in PHP 4.0.
// so, list your entities one by one here. I included some of the
$search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // strip out html tags
"'([\r\n])[\s]+'", // strip out white space
"'&(quot|#34|#034|#x22);'i", // replace html entities
"'&(amp|#38|#038|#x26);'i", // added hexadecimal values
"'&(lt|#60|#060|#x3c);'i",
"'&(gt|#62|#062|#x3e);'i",
"'&(euro|#8364);'i", // europe
"'&a(uml|UML);'", // german
chr(0xE4), // ANSI ä
chr(0xF6), // ANSI ö
chr(0xFC), // ANSI ü
chr(0xC4), // ANSI Ä
chr(0xD6), // ANSI Ö
chr(0xDC), // ANSI Ü
chr(0xDF), // ANSI ß
$text = preg_replace($search,$replace,$document);
/*======================================================================*\
Purpose: expand each link into a fully qualified URL
Input: $links the links to qualify
$URI the full URI to get the base from
Output: $expandedLinks the expanded links
\*======================================================================*/
function _expandlinks($links,$URI)
preg_match("/^[^\?]+/",$URI,$match);
$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
$match = preg_replace("|/$|","",$match);
$match_part = parse_url($match);
$match_part["scheme"]."://".$match_part["host"];
$search = array( "|^http://".preg_quote($this->host)."|i",
"|^(?!http://)(?!mailto:)|i",
$expandedLinks = preg_replace($search,$replace,$links);
/*======================================================================*\
Purpose: go get the http data from the server
Input: $url the url to fetch
$fp the current open file pointer
$body body contents to send if any (POST)
\*======================================================================*/
function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")
if($this->passcookies && $this->_redirectaddr)
$URI_PARTS = parse_url($URI);
$headers = $http_method." ".$url." ".$this->_httpversion."\r\n";
$headers .= "User-Agent: ".$this->agent."\r\n";
if(!empty($this->host) && !isset($this->rawheaders['Host'])) {
$headers .= "Host: ".$this->host;
if(!empty($this->port) && $this->port != 80)
$headers .= ":".$this->port;
if(!empty($this->accept))
$headers .= "Accept: ".$this->accept."\r\n";
if(!empty($this->referer))
$headers .= "Referer: ".$this->referer."\r\n";
if(!empty($this->cookies))
if(!is_array($this->cookies))
$this->cookies = (array)$this->cookies;
if ( count($this->cookies) > 0 ) {
$cookie_headers .= 'Cookie: ';
foreach ( $this->cookies as $cookieKey => $cookieVal ) {
$cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; ";
$headers .= substr($cookie_headers,0,-2) . "\r\n";
if(!empty($this->rawheaders))
if(!is_array($this->rawheaders))
$this->rawheaders = (array)$this->rawheaders;
foreach ( $this->rawheaders as $headerKey => $headerVal )
$headers .= $headerKey.": ".$headerVal."\r\n";
if(!empty($content_type)) {
$headers .= "Content-Type: $content_type";
if ($content_type == "multipart/form-data")
$headers .= "; boundary=".$this->_mime_boundary;
$headers .= "Content-Length: ".strlen($body)."\r\n";
if(!empty($this->user) || !empty($this->pass))
$headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n";
if(!empty($this->proxy_user))
$headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n";
// set the read timeout if needed
if ($this->read_timeout > 0)
socket_set_timeout($fp, $this->read_timeout);
$this->timed_out = false;
fwrite($fp,$headers.$body,strlen($headers.$body));
$this->_redirectaddr = false;
while($currentHeader = fgets($fp,$this->_maxlinelen))
if ($this->read_timeout > 0 && $this->_check_timeout($fp))
if($currentHeader == "\r\n")
// if a header begins with Location: or URI:, set the redirect
if(preg_match("/^(Location:|URI:)/i",$currentHeader))
// get URL portion of the redirect
preg_match("/^(Location:|URI:)[ ]+(.*)/i",chop($currentHeader),$matches);
// look for :// in the Location header to see if hostname is included
if(!preg_match("|\:\/\/|",$matches[2]))
// no host in the path, so prepend
$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
// eliminate double slash
if(!preg_match("|^/|",$matches[2]))
$this->_redirectaddr .= "/".$matches[2];
$this->_redirectaddr .= $matches[2];
$this->_redirectaddr = $matches[2];
if(preg_match("|^HTTP/|",$currentHeader))
if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
$this->status= $status[1];
$this->response_code = $currentHeader;
$this->headers[] = $currentHeader;
$_data = fread($fp, $this->maxlength);
if (strlen($_data) == 0) {
if ($this->read_timeout > 0 && $this->_check_timeout($fp))
// check if there is a redirect meta tag
if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
// have we hit our frame depth and is there frame src to fetch?
if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match))
$this->results[] = $results;
for($x=0; $x<count($match[1]); $x++)
$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host);
// have we already fetched framed content?
elseif(is_array($this->results))
$this->results[] = $results;
$this->results = $results;
/*======================================================================*\
Purpose: go get the https data from the server using curl
Input: $url the url to fetch
$body body contents to send if any (POST)
\*======================================================================*/
function _httpsrequest($url,$URI,$http_method,$content_type="",$body="")
if($this->passcookies && $this->_redirectaddr)
$URI_PARTS = parse_url($URI);
// GET ... header not needed for curl
//$headers[] = $http_method." ".$url." ".$this->_httpversion;
$headers[] = "User-Agent: ".$this->agent;
$headers[] = "Host: ".$this->host.":".$this->port;
$headers[] = "Host: ".$this->host;
if(!empty($this->accept))
$headers[] = "Accept: ".$this->accept;
if(!empty($this->referer))
$headers[] = "Referer: ".$this->referer;
if(!empty($this->cookies))
if(!is_array($this->cookies))
$this->cookies = (array)$this->cookies;
if ( count($this->cookies) > 0 ) {
$cookie_str = 'Cookie: ';
foreach ( $this->cookies as $cookieKey => $cookieVal ) {
$cookie_str .= $cookieKey."=".urlencode($cookieVal)."; ";
$headers[] = substr($cookie_str,0,-2);
if(!empty($this->rawheaders))
if(!is_array($this->rawheaders))
$this->rawheaders = (array)$this->rawheaders;
foreach ( $this->rawheaders as $headerKey => $headerVal )
$headers[] = $headerKey.": ".$headerVal;
if(!empty($content_type)) {
if ($content_type == "multipart/form-data")
$headers[] = "Content-Type: $content_type; boundary=".$this->_mime_boundary;
$headers[] = "Content-Type: $content_type";
$headers[] = "Content-Length: ".strlen($body);
if(!empty($this->user) || !empty($this->pass))
$headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass);