curl_setopt
(PHP 4 >= 4.0.2)
curl_setopt -- 为CURL调用设置一个选项
描述
bool curl_setopt (int ch, string option, mixed value)
curl_setopt()函数将为一个CURL会话设置选项。option参数是你想要的设置,value是这个选项给定的值。
下列选项的值将被作为长整形使用(在option参数中指定):
CURLOPT_INFILESIZE: 当你上传一个文件到远程站点,这个选项告诉PHP你上传文件的大小。
CURLOPT_VERBOSE: 如果你想CURL报告每一件意外的事情,设置这个选项为一个非零值。
CURLOPT_HEADER: 如果你想把一个头包含在输出中,设置这个选项为一个非零值。
CURLOPT_NOPROGRESS: 如果你不会PHP为CURL传输显示一个进程条,设置这个选项为一个非零值。
注意:PHP自动设置这个选项为非零值,你应该仅仅为了调试的目的来改变这个选项。
CURLOPT_NOBODY: 如果你不想在输出中包含body部分,设置这个选项为一个非零值。
CURLOPT_FAILONERROR: 如果你想让PHP在发生错误(HTTP代码返回大于等于300)时,不显示,设置这个选项为一人非零值。默认行为是返回一个正常页,忽略代码。
CURLOPT_UPLOAD: 如果你想让PHP为上传做准备,设置这个选项为一个非零值。
CURLOPT_POST: 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
CURLOPT_FTPLISTONLY: 设置这个选项为非零值,PHP将列出FTP的目录名列表。
CURLOPT_FTPAPPEND: 设置这个选项为一个非零值,PHP将应用远程文件代替覆盖它。
CURLOPT_NETRC: 设置这个选项为一个非零值,PHP将在你的 ~./netrc 文件中查找你要建立连接的远程站点的用户名及密码。
CURLOPT_FOLLOWLOCATION: 设置这个选项为一个非零值(象 'Location: ')的头,服务器会把它当做HTTP头的一部分发送(注意这是递归的,PHP将发送形如 'Location: '的头)。
CURLOPT_PUT: 设置这个选项为一个非零值去用HTTP上传一个文件。要上传这个文件必须设置CURLOPT_INFILE和CURLOPT_INFILESIZE选项.
CURLOPT_MUTE: 设置这个选项为一个非零值,PHP对于CURL函数将完全沉默。
CURLOPT_TIMEOUT: 设置一个长整形数,作为最大延续多少秒。
CURLOPT_LOW_SPEED_LIMIT: 设置一个长整形数,控制传送多少字节。
CURLOPT_LOW_SPEED_TIME: 设置一个长整形数,控制多少秒传送CURLOPT_LOW_SPEED_LIMIT规定的字节数。
CURLOPT_RESUME_FROM: 传递一个包含字节偏移地址的长整形参数,(你想转移到的开始表单)。
CURLOPT_SSLVERSION: 传递一个包含SSL版本的长参数。默认PHP将被它自己努力的确定,在更多的安全中你必须手工设置。
CURLOPT_TIMECONDITION: 传递一个长参数,指定怎么处理CURLOPT_TIMEVALUE参数。你可以设置这个参数为TIMECOND_IFMODSINCE 或 TIMECOND_ISUNMODSINCE。这仅用于HTTP。
CURLOPT_TIMEVALUE: 传递一个从1970-1-1开始到现在的秒数。这个时间将被CURLOPT_TIMEVALUE选项作为指定值使用,或被默认TIMECOND_IFMODSINCE使用。
The values of the following options will be treated as strings:
CURLOPT_URL: This is the URL address you want to retrieve using PHP. You can also set this option during initialization with the curl_init() function.
CURLOPT_USERPWD: Pass a string in the form of [username]:[password] and use PHP to connect.
CURLOPT_PROXYUSERPWD: Pass a string in the format [username]:[password] to connect to the HTTP proxy.
CURLOPT_RANGE: Pass a range you want to specify. It should be in 'X-Y' format, with X or Y being excluded. HTTP transfers also support several intervals, separated by commas (X-Y,N-M).
CURLOPT_POSTFIELDS: Pass a string containing all the data as an HTTP "POST" operation.
CURLOPT_REFERER: A string containing a 'referer' header in the HTTP request.
CURLOPT_USERAGENT: A string containing a 'user-agent' header in the HTTP request.
CURLOPT_FTPPORT: Pass an IP address containing the IP address used by the ftp 'POST' command. This POST command tells the remote server to connect to the IP address we specified. This string can be an IP address, a host name, a network interface name (under UNIX), or '-' (use the system default IP address).
CURLOPT_COOKIE: Pass a header connection containing an HTTP cookie.
CURLOPT_SSLCERT: Pass a string containing the certificate in PEM format.
CURLOPT_SSLCERTPASSWD: Pass a password containing the necessary password to use the CURLOPT_SSLCERT certificate.
CURLOPT_COOKIEFILE: Pass a string containing the name of the file containing cookie data. This cookie file can be in Netscape format, or it can be a stack of HTTP-style headers stored in the file.
CURLOPT_CUSTOMREQUEST: When making an HTTP request, pass a character to be used by GET or HEAD. Pass a string to be used instead of GET or HEAD when doing an HTTP request. This is useful for doing or another, more obscure, HTTP request.
Note: Don't do this before making sure your server supports the command.
The following options require a file description (obtained using the fopen() function):
CURLOPT_FILE: This file will be the output file you place the transfer to. The default is STDOUT.
CURLOPT_INFILE: This file is the input file you sent.
CURLOPT_WRITEHEADER: This file contains the header part of your output.
CURLOPT_STDERR: This file has errors written instead of stderr.
Example code: Tested
@header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
@header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
@header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
@header("Cache -Control: post-check=0, pre-check=0", false);
@header("Pragma: no-cache");
@header("content-type:text/html; charset =utf-8");
$url = 'http://s.jb51.net';
$querystring = $_SERVER["QUERY_STRING"];
$currentUrl = $_SERVER['SERVER_NAME '];
if($querystring != '') $querystring = $querystring . "&";
$querystring = $querystring . "SiteURL=" . $currentUrl;
if($querystring ! = '')
{
$url = $url . "?" . $querystring;
}
$ch = curl_init();
$timeout = 60; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$handles = curl_exec($ch);
//The following are replacements, which can be combined with server pseudo-static settings
$handles = preg_replace("/?page=([0-9]+)&categoryId=([0-9 ]+)/i","/fenlei/category-$1-$2.html",$handles);
$handles = preg_replace("/?categoryId=([0-9]+)/i"," /fenlei/category--$1.html",$handles);
$handles = preg_replace("/?page=([0-9]+)/i","/fenlei/category-$1.html" ,$handles);
$handles = preg_replace("/infodetail.aspx?ID=([0-9]+)/i","/fenlei/$1.html",$handles);
$ handles = str_replace("infolist.aspx","/fenlei/index.html",$handles);
$handles = str_replace("unionlist.aspx","unionlist.html",$handles);
echo $handles;
?>

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

转化方法:1、使用“mb_substr($url,stripos($url,"?")+1)”获取url的参数部分;2、使用“parse_str("参数部分",$arr)”将参数解析到变量中,并传入指定数组中,变量名转为键名,变量值转为键值。

在php中,可以利用ltrim()函数来去掉字符串首位的tab空白符,语法为“ltrim(string)”;当只给ltrim()函数传入一个参数,用于规定要检查的字符串时,可删除该字符串开始位置的空白字符(例空格、tab制表符、换行符等)。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
