PHP four ways to invoke a remote URL
1. Get content with file_get_contents in get mode
Example:
2. Open the URL with fopen and get the content in Get mode
Example:
3, using the File_get_contents function, the Post method to obtain the URL
$data = Array (' Test ' = ' hellword '); $data = Http_build_query ($data); $opts = Array (' http ' = = Array ( ' method ' = ' + ' POST ', ' header ' = ') ' content-type:application/ x-www-form-urlencoded\r\n ". " Content-length: ". Strlen ($data). "\ r \ n", ' content ' = $data ),); $context = Stream_context_create ($opts); $html = File_get_contents ($url, False, $context);
4, using the Curl Library, before using the Curl Library, you need to confirm that there is an open Curl extension
$ch = Curl_init (); $timeout = 5; curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_connecttimeout, $timeout); $file _contents = curl_exec ($ch); Curl_close ($ch); echo $file _contents;