[Network Programming] Several examples of php curl
Using PHP's cURL library can easily and effectively capture web pages. You only need to run a script and analyze the web pages you crawled, and then you can get the data you want programmatically. Whether you want to retrieve partial data from a link, take an XML file and import it into a database, or even simply retrieve the content of a web page, cURL is a powerful PHP library.
CURL Function Library (Client URL Library Function) in PHP
curl_close — close a curl session curl_copy_handle — copy all content and parameters of a curl connection resource curl_errno — return a numeric number containing error information of the current session curl_error — Returns a string containing error information for the current session curl_exec — Execute a curl session curl_getinfo — Get information about a curl connection resource handle curl_init — Initialize a curl session curl_multi_add_handle — Add a separate curl handle to a curl batch session Resources curl_multi_close — Close a batch handle resource curl_multi_exec — Parse a curl batch handle curl_multi_getcontent — Return the text stream of the obtained output curl_multi_info_read — Get the relevant transmission information of the currently parsed curl curl_multi_init — Initialize a curl batch handle Resources curl_multi_remove_handle — Remove a handle resource in the curl batch handle resource curl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected" curl_setopt_array — Set session parameters for a curl in the form of an array curl_setopt — Set session parameters for a curl curl_version — Get curl-related version information
The role of the curl_init() function is to initialize a curl session. The only parameter of the curl_init() function is optional and represents a URL address. The curl_exec() function is used to execute a curl session. The only parameter is the handle returned by the curl_init() function. The curl_close() function is used to close a curl session. The only parameter is the handle returned by the curl_init() function.
Example 1: Basic example
Example 2: POST data
sendSMS.php, which can accept two form fields, one is the phone number, and the other is the text message content.
$data = curl_exec();
curl_close($ch);
?﹥
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn