PHP 教程 在线

2540获取一个cURL连接资源句柄的信息 curl_init()

当前值为 :int 类型,设置最大输入值,当超过最大输入值时,弹出信息并清空输入数据!不超过则不弹出!

<input id="PAID_RATET"  type='text' class='k-textbox editableCell popover-show'
data-min="0" data-role="numerictextbox" title="提示:" data-container="body"
data-toggle="popover" data-content="输入最大值不可超过100%"
data-spinners="false" data-bind='value:PAID_RATE' onkeyup="limitInput(this);" />


function limitInput(o) {
    var value = o.value;
    var min = 1;
    var max = 100;
    if (parseInt(value) < min || parseInt(value) > max) {
        $(function () {
          $(function () { $('.popover-show').popover('show');});
        });
        o.value = '';
    }
}

尝试一下 »

详细(input):

1.最小值(kendo ui特性)

data-min="0"

2.设置不可输入英文(kendo ui 特性)

data-role="numerictextbox"

3.带入判断最大最小值的 js 事件

onkeyup="limitInput(this);

4.value 值

value:PAID_RATE 对应js代码中的 o.value = ''; 值。

扩展:

js 代码中的 [o.value = ''],可设置值,在input框内显示,实现另外一种类型的提示;

注:显示信息暂无法移除,需添加点击清空事件事件。

2539获取一个cURL连接资源句柄的信息 curl_init()

PHP 利用 CURL 发送 post get del put patch 请求

因为需要在 php 开发中对接其它接口需要用 php curl 去对接其它接口,我把他们封装成函数,希望能对大家有所帮助。

这里面是封装好的会自动把 data 数组转成 json 格式,同时解码输出的结果也是自动将 JSON 格式转换为数组格式输出:

发送 get 请求

function geturl($url){
        $headerArray =array("Content-type:application/json;","Accept:application/json");
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        $output = json_decode($output,true);
        return $output;
}

post 请求

function posturl($url,$data){
        $data  = json_encode($data);    
        $headerArray =array("Content-type:application/json;charset='utf-8'","Accept:application/json");
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output,true);
}

put 请求

function puturl($url,$data){
    $data = json_encode($data);
    $ch = curl_init(); //初始化CURL句柄 
    curl_setopt($ch, CURLOPT_URL, $url); //设置请求的URL
    curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //设为TRUE把curl_exec()结果转化为字串,而不是直接输出 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"PUT"); //设置请求方式
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//设置提交的字符串
    $output = curl_exec($ch);
    curl_close($ch);
    return json_decode($output,true);
}

delete 请求

function delurl($url,$data){
    $data  = json_encode($data);
    $ch = curl_init();
    curl_setopt ($ch,CURLOPT_URL,$put_url);
    curl_setopt ($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");   
    curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
    $output = curl_exec($ch);
    curl_close($ch);
    $output = json_decode($output,true);
}

2538获取一个cURL连接资源句柄的信息 curl_init()

PHP CURL 访问的如果是 https 协议,需要添加以下语句:

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false)

实例:

$url = 'https://www.facesho.com'; 
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);// 这个是主要参数
$data = curl_exec($curl); 
curl_close($curl);
var_dump($data);  

2537用于统计数组中所有值出现的次数 array_diff()

用这个来比较几个数组是否相同时要注意了:

array_diff($array1, $array2); 不管这两个数组是否相同都有可能返回的是空数组,因为它只返回 $array1 的差集,所以要验证是否相同的要相互比较才行,就像这样:

if( !array_diff($arr1, $arr2) && !array_diff($arr2, $arr1)){
    // 即相互都不存在差集,那么这两个数组就是相同的了,多数组也一样的道理
    return true;
}

2304PHP strripos() 函数

strripos — Find the position of the last occurrence of a case-insensitive substring in a string (PHP 5, PHP 7)

strripos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int

Find the numeric position of the last occurrence of needle in the haystack string.

strripos() is case-insensitive.

Parameters

haystack

The string to search in.

needle

If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. This behavior is deprecated as of PHP 7.3.0, and relying on it is highly discouraged. Depending on the intended behavior, the needle should either be explicitly cast to string, or an explicit call to chr() should be performed

offset

If zero or positive, the search is performed left to right skipping the first offset bytes of the haystack

If negative, the search is performed right to left skipping the last offset bytes of the haystack and searching for the first occurrence of needle

This is effectively looking for the last occurrence of needle before the last offset bytes

Return Values

Returns the position where the needle exists relative to the beginnning of the haystack string (independent of search direction or offset).

String positions start at 0, and not 1.

Returns FALSE if the needle was not found.

Warning

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE.

Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.