I was wondering is there a way to use PHP DOM cl开发者_开发知识库asses(currently using http://sourceforge.net/projects/simplehtmldom/ and doesn't seem to support it) and switch between server ips?
I need equivalent of 'CURLOPT_INTERFACE' that is used for curl, but for DOM in this case, as I don't want to use my account's shared IP, I want to use it's dedicated IP
Simply download the XML or HTML document with curl with the desired options (and CURLOPT_RETURNTRANSFER
), and then parse it with your preferred DOM implementation, like this:
$ch = curl_init('http://example.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_INTERFACE, 'eth0');
$content = curl_exec($ch);
$doc = new DOMDocument();
$doc->loadHtml($content);
echo 'Root node is ' . $doc->documentElement->tagName . '!';
精彩评论