PHP腾讯地图经纬度转百度地图经纬度/PHP cURL 带cookies模拟HTTP/PHP发送邮件

腾讯地图经纬度转百度地图经纬度

/**
* 中国正常GCJ02坐标---->百度地图BD09坐标
* 腾讯地图用的也是GCJ02坐标
* @param double $lat 纬度
* @param double $lng 经度
*/
function Convert_GCJ02_To_BD09($lat,$lng){
        $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
        $x = $lng;
        $y = $lat;
        $z =sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $x_pi);
        $theta = atan2($y, $x) + 0.000003 * cos($x * $x_pi);
        $lng = $z * cos($theta) + 0.0065;
        $lat = $z * sin($theta) + 0.006;
        return array('lng'=>$lng,'lat'=>$lat);
}

/**
* 百度地图BD09坐标---->中国正常GCJ02坐标
* 腾讯地图用的也是GCJ02坐标
* @param double $lat 纬度
* @param double $lng 经度
* @return array();
*/
function Convert_BD09_To_GCJ02($lat,$lng){
        $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
        $x = $lng - 0.0065;
        $y = $lat - 0.006;
        $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
        $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
        $lng = $z * cos($theta);
        $lat = $z * sin($theta);
        return array('lng'=>$lng,'lat'=>$lat);
}

php markdown解析

<?php
header("content-type:text/html;charset=utf-8");
require_once('Parsedown.php');
$text = '##Markdown有哪些功能?
* 方便的`导入导出`功能
    *  直接把一个markdown的文本文件拖放到当前这个页面就可以了
    *  导出为一个html格式的文件,样式一点也不会丢失
* 编辑和预览`同步滚动`,所见即所得(右上角设置)
* `VIM快捷键`支持,方便vim党们快速的操作 (右上角设置)
* 强大的`自定义CSS`功能,方便定制自己的展示
* 有数量也有质量的`主题`,编辑器和预览区域
* 完美兼容`Github`的markdown语法
* 预览区域`代码高亮`
* 所有选项自动记忆
';
$result = Parsedown::instance()->parse($text);
echo $result;

markdown下载链接:http://pan.baidu.com/s/1eQo3cBo


php输出页面所有变量

<?php
print_r(get_defined_vars());

此函数返回一个包含所有已定义变量列表的多维数组,这些变量包括环境变量、服务器变量和用户定义的变量。


获取所有已经定义的函数

<?php
get_defined_functions()

获取所有可用的模块

<?php
get_loaded_extensions()

获取指定模块的可用函数

<?php
get_extension_funcs()

该函数返回指定模块所有可用的函数。传入的参数(模块名称)必须是小写


获取关联数组的名字所有的常量和他们的值 —  (PHP 4 >= 4.1.0, PHP 5)

<?php
get_defined_constants()

get_declared_classes (PHP 4, PHP 5) —  获取由已定义类的名字所组成的数组

<?php
get_declared_classes()

get_included_files()(或者get_require_files) (PHP 4, PHP 5) —  获取由已定义类的名字所组成的数组

<?php
get_included_files()


PHP cURL 带cookies模拟HTTP

抓取个json数据,不知道哪里错了。遂重写一个

curl

<?php 
header("content-type:text/html;charset=utf8");
$curl = curl_init('https://www.phpcto.org/course/19/lesson/170');
// 不输出header头信息
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_COOKIE, ' PHPSESSID=q406pvav5da7st8q4ov6c482e0');
// 伪装浏览器
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36');
// 保存到字符串而不是输出
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$rs = curl_exec($curl);
curl_close($curl);
//echo $rs;
$arr=json_decode($rs,true);
print_r($arr);


一、PHPMailer

下载地址:http://pan.baidu.com/s/1o6LugJo

$mail = new PHPMailer(true);
$mail->IsSMTP();
$mail->CharSet='UTF-8';
$mail->SMTPAuth = true;
$mail->Port = 25;
$mail->Host = "smtp.163.com";//邮箱smtp地址,此处以163为例
$mail->Username = "你的邮箱账号";//你的邮箱账号
$mail->Password = "你的邮箱密码";//你的邮箱密码
$mail->From = "你的邮箱账号";//你的邮箱账号
$mail->FromName = get_option('blogname');
$to = $to;
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->WordWrap = 80;
//$mail->AddAttachment("f:/test.png"); //可以添加附件
$mail->IsHTML(true);
$mail->Send();
} catch (phpmailerException $e) {
// echo "邮件发送失败:".$e->errorMessage(); //测试的时候可以去掉此行的注释
}


QueryList提取HTML标签内容

QueryList下载地址:   http://pan.baidu.com/s/1sjlvTSh


由于要提取学校网站新闻标题和链接,首先想到的是正则,这次想换种方法去做,想到有QueryList这好东西,拿来试试

141830_Pg0o_2304951.png

再来看看其标签:

td下面的a标签

141916_KXP1_2304951.jpg


废话不多说,上代码:

<?php
require 'QueryList/QueryList.class.php';
$url = "http://www.hkxy.edu.cn/";
$reg = array(
    "title" => array("td>a","text"),
    "src" => array("td>a","href"),
);
//$rang = "[id^=post-]";
$hj = QueryList::Query($url,$reg);
//$hj = QueryList::Query($url,$reg,$rang);
for($i=0;$i<count($hj->jsonArr);$i++){
    //$hj->jsonArr[$i]['title']=html_entity_decode(($hj->jsonArr[$i]['title']),ENT_NOQUOTES,'utf-8');
    $hj->jsonArr[$i]['title']=str_replace('&#160;','',$hj->jsonArr[$i]['title']);
}
print_r($hj->jsonArr);
//echo $hj->getJSON();

再来看下效果

142016_Snp3_2304951.png


PHP两种获取URL状态码的方法


第一种,cURL:判断URL是否能访问.0为失败


$curl = curl_init(); 
//$url='http://113.57.132.2:83/login.aspx';
$url='http://www.hkxy.edu.cn';
curl_setopt($curl, CURLOPT_URL, $url); //设置URL 
curl_setopt($curl, CURLOPT_HEADER, 1); //获取Header 
curl_setopt($curl,CURLOPT_NOBODY,true); //Body就不要了吧,我们只是需要Head 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //数据存到成字符串吧,别给我直接输出到屏幕了 
curl_setopt($curl, CURLOPT_TIMEOUT, 7);
$data = curl_exec($curl); //开始执行啦~ 
echo curl_getinfo($curl,CURLINFO_HTTP_CODE); //我知道HTTPSTAT码哦~ 
curl_close($curl); //用完记得关掉他

第二种,$http_response_header


file_get_contents()超时设置:

$ctx = stream_context_create(array('http' => array('timeout' => 20)));

$result = @file_get_contents($url,false,$ctx);


<?php
function get_contents() {
  
file_get_contents("http://example.com");
  
var_dump($http_response_header);
}
get_contents();
var_dump($http_response_header);
?>

以上例程的输出类似于:

array(9) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  [1]=>
  string(35) "Date: Sat, 12 Apr 2008 17:30:38 GMT"
  [2]=>
  string(29) "Server: Apache/2.2.3 (CentOS)"
  [3]=>
  string(44) "Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT"
  [4]=>
  string(27) "ETag: "280100-1b6-80bfd280""
  [5]=>
  string(20) "Accept-Ranges: bytes"
  [6]=>
  string(19) "Content-Length: 438"
  [7]=>
  string(17) "Connection: close"
  [8]=>
  string(38) "Content-Type: text/html; charset=UTF-8"
}
NULL



PHP DES加密解密

<?php
class Security {
    public static function encrypt($input, $key) {
        $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
        $input = Security::pkcs5_pad($input, $size);
        $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
        $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
        mcrypt_generic_init($td, $key, $iv);
        $data = mcrypt_generic($td, $input);
        mcrypt_generic_deinit($td);
        mcrypt_module_close($td);
        $data = base64_encode($data);
        return $data;
    }
  
    private static function pkcs5_pad ($text, $blocksize) {
        $pad = $blocksize - (strlen($text) % $blocksize);
        return $text . str_repeat(chr($pad), $pad);
    }
  
    public static function decrypt($sStr, $sKey) {
        $decrypted= mcrypt_decrypt(
        MCRYPT_RIJNDAEL_128,
        $sKey,
        base64_decode($sStr),
        MCRYPT_MODE_ECB
    );
  
        $dec_s = strlen($decrypted);
        $padding = ord($decrypted[$dec_s-1]);
        $decrypted = substr($decrypted, 0, -$padding);
        return $decrypted;
    }   
}
 
 
 
 
$key = "rt94123456";
$data = "1234567890";
$value = Security::encrypt($data , $key );
echo $value.'<br/>';
echo Security::decrypt($value, $key );


编码转换

今天做了个模拟抓取CET成绩查询的,发现账号和姓名是正确的就是始终无法登录,最后一步步比对,发现GBK和UTF8的 unicode转换是不一样的。


$str = iconv("GB2312", "UTF-8", $str);

GBK转UTF8


php  excel_reader

今天需要将某个网站般去另一台服务器。设置好运行,显示一大堆Deprecated。
Deprecated: Assigning the return value of new by reference is deprecated in。
新服务器与旧服务器环境是一样的,后来查看php版本,发现旧服务器是 PHP 5.2.4 新的是PHP 5.3.2。之前了解到5.3 与 5.3之前的区别较大,于是查看php文档。

在5.3版本之后已经不允许在程序中使用"=&"符号

如果出现了Deprecated: Assigning the return value of new by reference is deprecated in 错误,
先找到出错的文件,查找下是不是在程序中使用了"=&",如发现使用了"=&"符号,将 "=&" 改成 "=" 即可解决问题。

$link =& $this->links[$linkKey];
// 改为
$link = $this->links[$linkKey];


转载于:https://my.oschina.net/rain21/blog/498457

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值