PHP Equivalent XML HTTP Request

They have: 82 posts

Joined: Oct 2001

Hey guys,

Does PHP have an equivalent of this code?

//ASP

Dim objXmlHttp
Dim strHTML

'// CREATE THE XML OBJECT
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")

'// REQUEST THE PAGE
objXmlHttp.open "GET", "http://www.mikeross.tv/linkads/displaylinks.asp?id=2", False

objXmlHttp.send

'// GET THE RESPONSE
strHTML = objXmlHttp.responseText

Set objXmlHttp = Nothing

Response.Write strHTML

Thank you very much!!

Mike

Blessed is the man who fears the LORD, who delights greatly in his commandments. Psalms 112:1

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

What does XML have to do with retrieving a URL?

you could try:
$html = [url=http://www.php.net/manual/en/function.file-get-contents.php"]file_get_contents[/url](http://www.mikeross.tv/linkads/displaylinks.asp?id=2);

or, if you want more control:
(I took this out of a function I wrote)

<?php
$url
= parse_url($url);

if (
strlen($url['port']==0)) $url['port'] = 80;

$fp = fsockopen ($url['host'], $url['port'], $errno, $errstr, 3);
if (!
$fp) {
    echo \
"ERROR: cannot access '$url'\n\n\";
    return false;
}
else {
   
$tmp_path = (strlen($url['query'])>0) ? \"$url[path]?$url[query]\" : $url['path'];
   
$tmp_host = (strlen($url['port'])>0) ? \"$url[host]:$url[port]\" : $url['host'];
   
   
$http_request[] = \"GET $tmp_path HTTP/1.0\";
   
$http_request[] = \"Host: $tmp_host\";
   
$http_request = implode(\"\r\n\", $http_request) . \"\r\n\r\n\";
   
    fputs (
$fp, $http_request);
    while (!feof(
$fp)) {
       
$http_response .= fread ($fp, 1024);
    }
    fclose (
$fp);
   
   
   
$tmp = strpos($http_response, \"\r\n\r\n\");
   
$headers = substr($http_response, 0, $tmp);
   
$data = substr($http_response, $tmp+4);

}
?>

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 82 posts

Joined: Oct 2001

The ASP code is really meant to return XML but I have used it to simply write the HTML contenets returned.

Thank you Mark!!

- Mike

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.