Skip to content

Instantly share code, notes, and snippets.

@natejacobson
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natejacobson/8970aa176e4a998b1858 to your computer and use it in GitHub Desktop.
Save natejacobson/8970aa176e4a998b1858 to your computer and use it in GitHub Desktop.
Get html or inner html for output elsewhere using php.
<?php
header("Content-Type: text/html; charset=utf-8");
function get_url_element_contents($url){
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);
$ret = end(explode('<element>' , $ret ));
$ret = substr($ret, 0, strrpos($ret, '</element>'));
print $ret;
}
function get_url_contents($url){
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);
print $ret;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment