php curl用法

 更新时间:2016年11月25日 15:52  点击:1564

在php教程使用curl时必须先在php.ini中开启extension=php_curl.dll前面的;去了,才行哦,curl是php中一款内置的浏览器,它可以模仿用户浏览信息进行网站浏览,等下面来看一实例。


function postpage($url)
{
$response = "";
$rd=rand(1,4);
$proxy='http://221.214.27.253:808';
if($rd==2) $proxy='http://222.77.14.56:8088';
if($rd==3) $proxy='http://202.98.123.126:8080';
if($rd==4) $proxy='http://60.14.97.38:8080';
if($url != "") {
$ch = curl_init($url);
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_returntransfer, true);
curl_setopt($ch, curlopt_proxy, $proxy);
$response = curl_exec($ch);
if(curl_errno($ch)) $response = "";
curl_close($ch);
}
return $response;
}

curl包括部份函数

curl_close — close a curl session
curl_copy_handle — copy a curl handle along with all of its preferences
curl_errno — return the last error number
curl_error — return a string containing the last error for the current session
curl_exec — perform a curl session
curl_getinfo — get information regarding a specific transfer
curl_init — initialize a curl session
curl_multi_add_handle — add a normal curl handle to a curl multi handle
curl_multi_close — close a set of curl handles
curl_multi_exec — run the sub-connections of the current curl handle
curl_multi_getcontent — return the content of a curl handle if curlopt_returntransfer is set
curl_multi_info_read — get information about the current transfers
curl_multi_init — returns a new curl multi handle
curl_multi_remove_handle — remove a multi handle from a set of curl handles
curl_multi_select — wait for activity on any curl_multi connection
curl_setopt_array — set multiple options for a curl transfer
curl_setopt — set an option for a curl transfer
curl_version — gets curl version information

php教程 效率的字符串处理方法

<?php
$str = array(
"helloworld",
"howareyou",
"cpufrequency",
"windows7ready",
"newedition2",
"downloadurllist",
"heisasuperhero",
);

//你的解决方法


/*
正确添加空格后应为:
"helloworld" = "hello world"
"howareyou" = "how are you"
"cpufrequency" = "cpu frequency"
"windows7ready" = "windows 7 ready"
"newedition2" = "new edition 2"
"downloadurllist" = "download url list"
"heisasuperhero" = "he is a super hero"
*/

?>

程序代码

function transfer($input) {
        $newarray = array();
        foreach($input as $i) {
                $arr = str_split($i);
                $word = '';
                foreach($arr as $a) {
                        $ascii = ord($a);
                        $lastword = substr($word, -1);
                        $ascii_1 = ord($lastword);
                        $lastword_ = substr($word, -2, 1);
                        if($ascii > 64 && $ascii < 91) {
                                if($ascii_1 > 96 && $ascii_1 < 122) {
                                        $word .= ' '.$a;
                                } else {
                                        $word .= $a;
                                }
                        } elseif($ascii > 96 && $ascii < 122) {
                                if($ascii_1 > 64 && $ascii_1 < 91) {
                                        if(strlen($word) == 1) {
                                                $word .= $a;
                                        } else {
                                                if(ord($lastword_) == 32) {
                                                        $word .= $a;
                                                } else {
                                                        $word = substr($word, 0, -1).' '.$lastword.$a;
                                                }
                                        }
                                } else {
                                        $word .= $a;
                                }
                        } else {
                                if(strlen($word) == 0) {
                                        $word .= $a;
                                } else {
                                        $word .= ' '.$a;
                                }
                        }
                }
                $newarray[$i] = $word;
        }
        return $newarray;
}

print_r(transfer($str));

一、   概述

php教程-excelreader   是一个读取 excel xsl   文件内容的一个 php   类。

它的下载网址:  http://sourceforge.net/projects/phpexcelreader/

本博客下载地址:phpexcelreader.zip

测试用excel文件:测试.xls

文件名: phpexcelreader.zip

包含两个必需文件: oleread.inc   、 reader.php   。其它文件是一个应用例子 ,   自述文件等

二、   文件使用

首先 ,   包含 reader   类文件: require_once " reader.php";

新建一个实例: $xl_reader= new spreadsheet_excel_reader ( );

设定编码信息: $xl_reader ->setoutputencoding('utf-8');//不设定可能会是乱码 要和网页显示编码一致

读取 excel   文件信息: $xl_reader->read("filename.xls");

它将导出 excel   文件中所有可以识别的数据存储在一个对象中。数据存储在 2   个数组中,目前没有提供方法 /   函数访问这些数据 .   可以像下面这样简单的使用数组名。

sheets   数组包含了读取入对象的大量数据。它将导出 excel   文件中所有可以识别的数据存储在一个 2   维数组中 $xl_reader->sheets[x][y]   。 x  为文档中的表序号, y  是以下的某个参数 :

①        numrows -- int --  表的行数

例如: $rows = $xl_reader->sheets[0]['numrows']

②        numcols -- int --  表的列数

例如: $cols = $xl_reader->sheets[0]['numcols']

③        cells -- array --  表的实际内容。是一个 [row][column]   格式的 2   维数组

    例如: $cell_2_4 = $xl_reader->sheets[0]['cells'][2][4] //   行 2,   列 4   中的数据

④        cellsinfo -- array --  表格中不同数据类型的信息。每个都包含了表格的原始数据和类型。这个数组包含 2   部分: raw --  表格原始数据; type --  数据类型。

注:只显示非文本数据信息。

例如: $cell_info = $xl_reader[0]['cellsinfo'][2][4]

$cell_info['raw'] is the raw data from the cell

$cell_info['type'] is the data type

$xl_reader->sheets

原理是从url中提取关键词。参数说明:url及关键词前的字符,然后进行处理与来源判断是那个搜索引擎,这样保存到数据就就行了。

<?php教程
//

$search_url = isset($_get['url'])?$_get['url']:''; //代表传入的地址
/*$search_url = urldecode($search_url);
print_r($search_url);
*/

$config = array(
    "s1"=>array(
        "domain" => "google.com",
        "kw" => "q",
        "charset" => "utf-8"
    ),
    "s3"=>array(
        "domain" => "google.cn",
        "kw" => "q",
        "charset" => "utf-8"
    ),
    "s4"=>array(
        "domain" => "baidu.com",
        "kw" => "wd",
        "charset" => "gbk"
    ),
    "s5"=>array(
        "domain" => "soso.com",
        "kw" => "q",
        "charset" => "utf-8"
    ),
    "s6"=>array(
        "domain" => "yahoo.com",
        "kw" => "q",
        "charset" => "utf-8"
    ),
    "s7"=>array(
        "domain" => "bing.com",
        "kw" => "q",
        "charset" => "utf-8"
    ),
    "s8"=>array(
        "domain" => "sogou.com",
        "kw" => "query",
        "charset" => "gbk"
    ),
    "s9"=>array(
        "domain" => "youdao.com",
        "kw" => "q",
        "charset" => "utf-8"
    ),
);

//函数作用:从url中提取关键词。参数说明:url及关键词前的字符。
function get_keyword($url,$kw_start)

{
    $start = stripos($url,$kw_start);
    $url = substr($url,$start+strlen($kw_start));
    $start = stripos($url,'&');
    if ($start>0)
    {
        $start=stripos($url,'&');
        $s_s_keyword=substr($url,0,$start);
    }
    else
    {
        $s_s_keyword=substr($url,0);
    }
    return $s_s_keyword;
}

$arr_key = array();
foreach($config as $item){
    $sh = preg_match("/b{$item['domain']}b/",$search_url);
    if($sh){
        $query = $item['kw']."=";

        $s_s_keyword = get_keyword($search_url,$query);
        $f_skey=urldecode($s_s_keyword);
        if($item['charset']=="utf-8"){
            $f_skey=iconv( "utf-8","gb2312//ignore",$f_skey); //最终提取的关键词
        }
        $keys = explode(" ",$f_skey);
        $arr_key[$item['domain']] = $keys;
    }
}
echo "<pre>";
print_r($arr_key);

?>
<form action="index.php" method="get">
    <input name="url" size="80"><button type="submit">go</button>
</form>

迅雷地址正则匹配代码

thunder://[a-za-z0-9]*


perl:
thunder://.+
用preg_replace()函数。

迅雷地址分不分大小写?不分的话用pregi_replace()

[!--infotagslink--]

相关文章

  • C#中using的三种用法

    using 指令有两个用途: 允许在命名空间中使用类型,以便您不必限定在该命名空间中使用的类型。 为命名空间创建别名。 using 关键字还用来创建 using 语句 定义一个范围,将在此...2020-06-25
  • 源码分析系列之json_encode()如何转化一个对象

    这篇文章主要介绍了源码分析系列之json_encode()如何转化一个对象,对json_encode()感兴趣的同学,可以参考下...2021-04-22
  • php中去除文字内容中所有html代码

    PHP去除html、css样式、js格式的方法很多,但发现,它们基本都有一个弊端:空格往往清除不了 经过不断的研究,最终找到了一个理想的去除html包括空格css样式、js 的PHP函数。...2013-08-02
  • index.php怎么打开?如何打开index.php?

    index.php怎么打开?初学者可能不知道如何打开index.php,不会的同学可以参考一下本篇教程 打开编辑:右键->打开方式->经文本方式打开打开运行:首先你要有个支持运行PH...2017-07-06
  • PHP中func_get_args(),func_get_arg(),func_num_args()的区别

    复制代码 代码如下:<?php function jb51(){ print_r(func_get_args()); echo "<br>"; echo func_get_arg(1); echo "<br>"; echo func_num_args(); } jb51("www","j...2013-10-04
  • PHP编程 SSO详细介绍及简单实例

    这篇文章主要介绍了PHP编程 SSO详细介绍及简单实例的相关资料,这里介绍了三种模式跨子域单点登陆、完全跨单点域登陆、站群共享身份认证,需要的朋友可以参考下...2017-01-25
  • PHP实现创建以太坊钱包转账等功能

    这篇文章主要介绍了PHP实现创建以太坊钱包转账等功能,对以太坊感兴趣的同学,可以参考下...2021-04-20
  • iscroll.js 用法介绍

    最新版下载: http://www.csdn123.com/uploadfile/2015/0428/20150428062734485.zip 概要 iScroll 4 这个版本完全重写了iScroll这个框架的原始代码。这个项目的产生...2016-05-19
  • C#中的try catch finally用法分析

    这篇文章主要介绍了C#中的try catch finally用法,以实例形式分析了try catch finally针对错误处理时的不同用法,具有一定的参考借鉴价值,需要的朋友可以参考下...2020-06-25
  • C++中cin的用法详细

    这篇文章主要介绍了C++中cin的用法详细,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-04-25
  • php微信公众账号开发之五个坑(二)

    这篇文章主要为大家详细介绍了php微信公众账号开发之五个坑,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2016-10-02
  • ThinkPHP使用心得分享-ThinkPHP + Ajax 实现2级联动下拉菜单

    首先是数据库的设计。分类表叫cate.我做的是分类数据的二级联动,数据需要的字段有:id,name(中文名),pid(父id). 父id的设置: 若数据没有上一级,则父id为0,若有上级,则父id为上一级的id。数据库有内容后,就可以开始写代码,进...2014-05-31
  • PHP如何通过date() 函数格式化显示时间

    这篇文章主要介绍了PHP如何通过date() 函数格式化显示时间,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-11-13
  • PHP+jQuery+Ajax实现多图片上传效果

    今天我给大家分享的是在不刷新页面的前提下,使用PHP+jQuery+Ajax实现多图片上传的效果。用户只需要点击选择要上传的图片,然后图片自动上传到服务器上并展示在页面上。...2015-03-15
  • golang与php实现计算两个经纬度之间距离的方法

    这篇文章主要介绍了golang与php实现计算两个经纬度之间距离的方法,结合实例形式对比分析了Go语言与php进行经纬度计算的相关数学运算技巧,需要的朋友可以参考下...2016-07-29
  • 示例详解react中useState的用法

    useState 通过在函数组件里调用它来给组件添加一些内部 state,React 会在重复渲染时保留这个 state,接下来通过一个示例来看看怎么使用 useState吧...2021-06-04
  • PHP如何使用cURL实现Get和Post请求

    这篇文章主要介绍了PHP如何使用cURL实现Get和Post请求,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-07-11
  • 谈谈PHP中相对路径的问题与绝对路径的使用

    经常看到有人踩在了PHP路径的坑上面了,感觉有必要来说说PHP中相对路径的一些坑,以及PHP中绝对路径的使用,下面一起来看看。 ...2016-08-24
  • Delphi常用关键字用法详解

    这篇文章主要介绍了Delphi常用关键字用法,包括了各个常用的关键字及其详细用法,需要的朋友可以参考下...2020-06-30
  • PHP中print_r、var_export、var_dump用法介绍

    文章详细的介绍了关于PHP中print_r、var_export、var_dump区别比较以及这几个在php不同的应用中的用法,有需要的朋友可以参考一下 可以看出print_r跟var_export都...2016-11-25