13c01-1.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 26 行
PHP
26 行
<?php// Create a function to handle the posting of datafunction http_post($url, $post) { // Initialize a cURL session: $c = curl_init(); // Set the URL that we are going to talk to: curl_setopt($c, CURLOPT_URL, $url); // Now tell cURL that we are doing a POST, and give it the data: curl_setopt($c, CURLOPT_POST, true); curl_setopt($c, CURLOPT_POSTFIELDS, $post); // Tell cURL to return the output of the page, instead of echo'ing it: curl_setopt ($c, CURLOPT_RETURNTRANSFER, true); // Now, execute the request, and return the data that we receive: return curl_exec($c);}// Create some data that we want to send as a post:$fields = array('data' => 'Jonathan Swift', 'idx' => 5783);// Actually perform the post to a url:echo http_post('http://example.com/script.php', http_build_query($fields));?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?