分享淘宝API辅助函数-适用CI框架

 更新时间:2016年11月25日 16:21  点击:1766
本文章给各位同学介绍分享淘宝API辅助函数-适用CI框架,有需要了解的朋友可参考。

最近在重写一个淘宝客的网站,考虑到以后的拓展性,所以把它整合进CI里面了,这就出现个问题了,淘宝的SDK怎么整合进类库呢?仔细阅读淘宝API文档后,发现一个非SDK调用方法,我在这基础上加以修改整合成CI的helper函数,现在把源码分享给大家,希望帮到有需要的同学。

    调用方法很简单,传入一个数组参数,其中method是你打算调用的API接口,其余的参数根据API接口的实际需要填入。我这里给个调用例子给大家看下。

 

 代码如下 复制代码


  
$paramArr = array(   
    ’method’    => ’taobao.taobaoke.items.get’,  //API名称   
    ’fields’    =>’num_iid,title,nick,pic_url,price,click_url,seller_credit_score,   
commission,commission_rate,volume’,   
    ’pid’       =>YOUR PID,   
    ’page_size’ =>YOUR PAGE_SIZE,   
    ’sort’      =>YOUR SORT,   
    ’keyword’   =>your keyword,   
);   
$this->load->helper(‘taoapi’);   
$result['item_list'] = send($paramArr);  

现在memcache在服务器缓存应用比较广泛,下面我来介绍memcache实现消息队列等待的一个例子,有需要了解的朋友可参考。

memche消息队列的原理就是在key上做文章,用以做一个连续的数字加上前缀记录序列化以后消息或者日志。然后通过定时程序将内容落地到文件或者数据库。


php实现消息队列的用处比如在做发送邮件时发送大量邮件很费时间的问题,那么可以采取队列。
方便实现队列的轻量级队列服务器是:
starling支持memcache协议的轻量级持久化服务器
https://github.com/starling/starling
Beanstalkd轻量、高效,支持持久化,每秒可处理3000左右的队列
http://kr.github.com/beanstalkd/
php中也可以使用memcache/memcached来实现消息队列。

 代码如下 复制代码

<?php
/**
* Memcache 消息队列类
*/

class QMC {
const PREFIX = 'ASDFASDFFWQKE';

/**
* 初始化mc
* @staticvar string $mc
* @return Memcache
*/
static private function mc_init() {
static $mc = null;
if (is_null($mc)) {
$mc = new Memcache;
$mc->connect('127.0.0.1', 11211);
}
return $mc;
}
/**
* mc 计数器,增加计数并返回新的计数
* @param string $key   计数器
* @param int $offset   计数增量,可为负数.0为不改变计数
* @param int $time     时间
* @return int/false    失败是返回false,成功时返回更新计数器后的计数
*/
static public function set_counter( $key, $offset, $time=0 ){
$mc = self::mc_init();
$val = $mc->get($key);
if( !is_numeric($val) || $val < 0 ){
$ret = $mc->set( $key, 0, $time );
if( !$ret ) return false;
$val = 0;
}
$offset = intval( $offset );
if( $offset > 0 ){
return $mc->increment( $key, $offset );
}elseif( $offset < 0 ){
return $mc->decrement( $key, -$offset );
}
return $val;
}

/**
* 写入队列
* @param string $key
* @param mixed $value
* @return bool
*/
static public function input( $key, $value ){
$mc = self::mc_init();
$w_key = self::PREFIX.$key.'W';
$v_key = self::PREFIX.$key.self::set_counter($w_key, 1);
return $mc->set( $v_key, $value );
}
/**
* 读取队列里的数据
* @param string $key
* @param int $max  最多读取条数
* @return array
*/
static public function output( $key, $max=100 ){
$out = array();
$mc = self::mc_init();
$r_key = self::PREFIX.$key.'R';
$w_key = self::PREFIX.$key.'W';
$r_p   = self::set_counter( $r_key, 0 );//读指针
$w_p   = self::set_counter( $w_key, 0 );//写指针
if( $r_p == 0 ) $r_p = 1;
while( $w_p >= $r_p ){
if( --$max < 0 ) break;
$v_key = self::PREFIX.$key.$r_p;
$r_p = self::set_counter( $r_key, 1 );
$out[] = $mc->get( $v_key );
$mc->delete($v_key);
}
return $out;
}
}
/**
使用方法:
QMC::input($key, $value );//写入队列
$list = QMC::output($key);//读取队列
*/
?>


基于PHP共享内存实现的消息队列:

 代码如下 复制代码

<?php
/**
* 使用共享内存的PHP循环内存队列实现
* 支持多进程, 支持各种数据类型的存储
* 注: 完成入队或出队操作,尽快使用unset(), 以释放临界区
*
* @author wangbinandi@gmail.com
* @created 2009-12-23
*/
class ShmQueue
{
private $maxQSize = 0; // 队列最大长度

private $front = 0; // 队头指针
private $rear = 0;  // 队尾指针

private $blockSize = 256;  // 块的大小(byte)
private $memSize = 25600;  // 最大共享内存(byte)
private $shmId = 0;

private $filePtr = './shmq.ptr';

private $semId = 0;
public function __construct()
{
$shmkey = ftok(__FILE__, 't');

$this->shmId = shmop_open($shmkey, "c", 0644, $this->memSize );
$this->maxQSize = $this->memSize / $this->blockSize;

// 申?一个信号量
$this->semId = sem_get($shmkey, 1);
sem_acquire($this->semId); // 申请进入临界区

$this->init();
}

private function init()
{
if ( file_exists($this->filePtr) ){
$contents = file_get_contents($this->filePtr);
$data = explode( '|', $contents );
if ( isset($data[0]) && isset($data[1])){
$this->front = (int)$data[0];
$this->rear  = (int)$data[1];
}
}
}

public function getLength()
{
return (($this->rear - $this->front + $this->memSize) % ($this->memSize) )/$this->blockSize;
}

public function enQueue( $value )
{
if ( $this->ptrInc($this->rear) == $this->front ){ // 队满
return false;
}

$data = $this->encode($value);
shmop_write($this->shmId, $data, $this->rear );
$this->rear = $this->ptrInc($this->rear);
return true;
}

public function deQueue()
{
if ( $this->front == $this->rear ){ // 队空
return false;
}
$value = shmop_read($this->shmId, $this->front, $this->blockSize-1);
$this->front = $this->ptrInc($this->front);
return $this->decode($value);
}

private function ptrInc( $ptr )
{
return ($ptr + $this->blockSize) % ($this->memSize);
}

private function encode( $value )
{
$data = serialize($value) . "__eof";
echo '';

echo strlen($data);
echo '';

echo $this->blockSize -1;
echo '';

if ( strlen($data) > $this->blockSize -1 ){
throw new Exception(strlen($data)." is overload block size!");
}
return $data;
}

private function decode( $value )
{
$data = explode("__eof", $value);
return unserialize($data[0]);
}

public function __destruct()
{
$data = $this->front . '|' . $this->rear;
file_put_contents($this->filePtr, $data);

sem_release($this->semId); // 出临界区, 释放信号量
}
}

/*
// 进队操作
$shmq = new ShmQueue();
$data = 'test data';
$shmq->enQueue($data);
unset($shmq);
// 出队操作
$shmq = new ShmQueue();
$data = $shmq->deQueue();
unset($shmq);
*/
?>

对于一个很大的消息队列,频繁进行进行大数据库的序列化 和 反序列化,有太耗费。下面是我用PHP 实现的一个消息队列,只需要在尾部插入一个数据,就操作尾部,不用操作整个消息队列进行读取,与操作。但是,这个消息队列不是线程安全的,我只是尽量的避免了冲突的可能性。如果消息不是非常的密集,比如几秒钟才一个,还是可以考虑这样使用的。
如果你要实现线程安全的,一个建议是通过文件进行锁定,然后进行操作。下面是代码:
代码如下:

 代码如下 复制代码
class Memcache_Queue
{
private $memcache;
private $name;
private $prefix;
function __construct($maxSize, $name, $memcache, $prefix = "__memcache_queue__")
{
if ($memcache == null) {
throw new Exception("memcache object is null, new the object first.");
}
$this->memcache = $memcache;
$this->name = $name;
$this->prefix = $prefix;
$this->maxSize = $maxSize;
$this->front = 0;
$this->real = 0;
$this->size = 0;
}
function __get($name)
{
return $this->get($name);
}
function __set($name, $value)
{
$this->add($name, $value);
return $this;
}
function isEmpty()
{
return $this->size == 0;
}
function isFull()
{
return $this->size == $this->maxSize;
}
function enQueue($data)
{
if ($this->isFull()) {
throw new Exception("Queue is Full");
}
$this->increment("size");
$this->set($this->real, $data);
$this->set("real", ($this->real + 1) % $this->maxSize);
return $this;
}
function deQueue()
{
if ($this->isEmpty()) {
throw new Exception("Queue is Empty");
}
$this->decrement("size");
$this->delete($this->front);
$this->set("front", ($this->front + 1) % $this->maxSize);
return $this;
}
function getTop()
{
return $this->get($this->front);
}
function getAll()
{
return $this->getPage();
}
function getPage($offset = 0, $limit = 0)
{
if ($this->isEmpty() || $this->size < $offset) {
return null;
}
$keys[] = $this->getKeyByPos(($this->front + $offset) % $this->maxSize);
$num = 1;
for ($pos = ($this->front + $offset + 1) % $this->maxSize; $pos != $this->real; $pos = ($pos + 1) % $this->maxSize)
{
$keys[] = $this->getKeyByPos($pos);
$num++;
if ($limit > 0 && $limit == $num) {
break;
}
}
return array_values($this->memcache->get($keys));
}
function makeEmpty()
{
$keys = $this->getAllKeys();
foreach ($keys as $value) {
$this->delete($value);
}
$this->delete("real");
$this->delete("front");
$this->delete("size");
$this->delete("maxSize");
}
private function getAllKeys()
{
if ($this->isEmpty())
{
return array();
}
$keys[] = $this->getKeyByPos($this->front);
for ($pos = ($this->front + 1) % $this->maxSize; $pos != $this->real; $pos = ($pos + 1) % $this->maxSize)
{
$keys[] = $this->getKeyByPos($pos);
}
return $keys;
}
private function add($pos, $data)
{
$this->memcache->add($this->getKeyByPos($pos), $data);
return $this;
}
private function increment($pos)
{
return $this->memcache->increment($this->getKeyByPos($pos));
}
private function decrement($pos)
{
$this->memcache->decrement($this->getKeyByPos($pos));
}
private function set($pos, $data)
{
$this->memcache->set($this->getKeyByPos($pos), $data);
return $this;
}
private function get($pos)
{
return $this->memcache->get($this->getKeyByPos($pos));
}
private function delete($pos)
{
return $this->memcache->delete($this->getKeyByPos($pos));
}
private function getKeyByPos($pos)
{
return $this->prefix . $this->name . $pos;
}
}
自己重写的一个php QQ第三方登陆SDK程序代码,官方的不敢恭维了所以自己再写了一个


主要是考虑到QQ的PHP SDK写的真是太烂了,纯属是普及API知识,而不是到手就可以部署的类库。。反正自己都写了一个了,就拿出来分享下。。

什么也不多说,直接上代码。

 

Qq_sdk.php

 

 代码如下 复制代码

<?php

/**

* QQ开发平台 SDK

* 作者:偶尔陶醉

* blog: www.stutostu.com

*/ 

 

class Qq_sdk{ 

 

//配置APP参数

private $app_id = 你的APP ID; 

private $app_secret = ‘你的APP_secret’; 

private $redirect = 你的回调地址;

 

function __construct() 

 

 

/**

* [get_access_token 获取access_token]

* @param [string] $code [登陆后返回的$_GET['code']]

* @return [array] [expires_in 为有效时间 , access_token 为授权码 ; 失败返回 error , error_description ]

*/ 

function get_access_token($code) 

//获取access_token

$token_url = ‘https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&’

. ‘client_id=’ . $this->app_id . ‘&redirect_uri=’ . urlencode($this->redirect)//回调地址

. ‘&client_secret=’ . $this->app_secret . ‘&code=’ . $code; 

$token = array(); 

//expires_in 为access_token 有效时间增量 

parse_str($this->_curl_get_content($token_url), $token); 

 

return $token; 

 

/**

* [get_open_id 获取用户唯一ID,openid]

* @param [string] $token [授权码]

* @return [array] [成功返回client_id 和 openid ;失败返回error 和 error_msg]

*/ 

function get_open_id($token) 

$str = $this->_curl_get_content(‘https://graph.qq.com/oauth2.0/me?access_token=’ . $token);

if (strpos($str, “callback”) !== false) 

$lpos = strpos($str, “(“); 

$rpos = strrpos($str, “)”); 

$str = substr($str, $lpos + 1, $rpos – $lpos -1); 

$user = json_decode($str, TRUE); 

 

return $user; 

 

/**

* [get_user_info 获取用户信息]

* @param [string] $token [授权码]

* @param [string] $open_id [用户唯一ID]

* @return [array] [ret:返回码,为0时成功。msg为错误信息,正确返回时为空。...params]

*/ 

function get_user_info($token, $open_id) 

 

//组装URL

$user_info_url = ‘https://graph.qq.com/user/get_use
r_info?’

. ‘access_token=’ . $token 

. ‘&oauth_consumer_key=’ . $this->app_id 

. ‘&openid=’ . $open_id 

. ‘&format=json’; 

 

$info = json_decode($this->_curl_get_content($user_info_url), TRUE); 

 

return $info; 

 

private function _curl_get_content($url) 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 

curl_setopt($ch, CURLOPT_URL, $url); 

//设置超时时间为3s

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 3); 

$result = curl_exec($ch); 

curl_close($ch); 

 

return $result; 

 

 

/* end of Qq_sdk.php */ 

 

 

使用方法:在你网站上放置超链接,地址为:https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=你的APP_ID&redirect_uri=你的回调地址

在回调地址上调用我上面这个qq_sdk即可。

demo如下:

 代码如下 复制代码

 

if(empty($_GET['code'])) 

exit(‘参数非法’); 

 

include(‘qq_sdk’); 

$qq_sdk = new Qq_sdk(); 

$token = $qq_sdk->get_access_token($_GET['code']); 

print_r($token); 

 

$open_id = $qq_sdk->get_open_id($token['access_token']); 

print_r($open_id); 

 

 

$user_info = $qq_sdk->get_user_info($token['access_token'], $open_id['openid']); 

print_r($user_info); 

由于使用php来写图片主色调识别功能太麻烦了,所以我给大家介绍利用利用k-means聚类算法识别图片主色调方法,比php要己100倍哦。

识别图片主色调这个,网上貌似有几种方法,不过,最准确,最优雅的解决方案还是利用聚类算法来做。。。

直接上代码。。。。不过,我测试结果表示,用PHP来做,效率不佳,PHP不适合做这种大规模运算~~~,用nodejs做 效率可以高出100倍左右。。。

 代码如下 复制代码

<?php 

$start = microtime(TRUE); 

main(); 

 

function main($img = ‘colors_files/T1OX3eXldXXXcqfYM._111424.jpg’) 

 

 

list($width, $height, $mime_code) = getimagesize($img); 

 

$im = null; 

$point = array(); 

switch ($mime_code) 

# jpg 

case 2: 

$im =imagecreatefromjpeg($img); 

break; 

 

# png 

case 3: 

 

default: 

exit(‘擦 ,什么图像?解析不了啊’); 

 

$new_width = 100; 

$new_height = 100; 

$pixel = imagecreatetruecolor($new_width, $new_height); 

imagecopyresampled($pixel, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 

 

run_time(); 

 

$i = $new_width; 

while ($i–) 

# reset高度 

$k = $new_height; 

while ($k–) 

$rgb = ImageColorAt($im, $i, $k); 

array_push($point, array(‘r’=>($rgb >> 16) & 0xFF, ‘g’=>($rgb >> 8) & 0xFF, ‘b’=>$rgb & 0xFF)); 

imagedestroy($im); 

imagedestroy($pixel); 

 

run_time(); 

 

$color = kmeans($point); 

 

run_time(); 

 

foreach ($color as $key => $value) 

&nb
sp; { 

echo ‘<br><span style=“background-color:’ . RGBToHex($value[0]) . ‘” >’ . RGBToHex($value[0]) . ‘</span>’; 

 

 

function run_time() 

global $start; 

echo ‘<br/>消耗:’, microtime(TRUE) – $start; 

 

function kmeans($point=array(), $k=3, $min_diff=1) 

global $ii; 

$point_len = count($point); 

$clusters = array(); 

$cache = array(); 

 

 

for ($i=0; $i < 256; $i++) 

$cache[$i] = $i*$i; 

 

# 随机生成k值 

$i = $k; 

$index = 0; 

while ($i–) 

$index = mt_rand(1,$point_len-100); 

array_push($clusters, array($point[$index], array($point[$index]))); 

 

 

run_time(); 

$point_list = array(); 

 

$run_num = 0; 

 

while (TRUE) 

foreach ($point as $value) 

$smallest_distance = 10000000; 

 

# 求出距离最小的点 

# index用于保存point最靠近的k值 

$index = 0; 

$i = $k; 

while ($i–) 

$distance = 0; 

foreach ($value as $key => $p1) 

&n
bsp; if ($p1 > $clusters[$i][0][$key]) 

$distance += $cache[$p1 - $clusters[$i][0][$key]]; 

else 

$distance += $cache[$clusters[$i][0][$key] – $p1]; 

 

$ii++; 

 

if ($distance < $smallest_distance) 

$smallest_distance = $distance; 

$index = $i; 

$point_list[$index][] = $value; 

 

$diff = 0; 

# 1个1个迭代k值 

$i = $k; 

while ($i–) 

$old = $clusters[$i]; 

 

# 移到到队列中心 

$center = calculateCenter($point_list[$i], 3); 

# 形成新的k值集合队列 

$new_cluster = array($center, $point_list[$i]); 

$clusters[$i] = $new_cluster; 

 

# 计算新的k值与队列所在点的位置 

$diff = euclidean($old[0], $center); 

 

# 判断是否已足够聚合 

if ($diff < $min_diff) 

break; 
>

 

echo ‘—>’.$ii; 

 

return $clusters; 

 

# 计算2点距离 

$ii = 0; 

function euclidean($p1, $p2) 

 

$s = 0; 

foreach ($p1 as $key => $value) 

 

$temp = ($value – $p2[$key]); 

$s += $temp*$temp; 

 

return sqrt($s); 

 

 

# 移动k值到所有点的中心 

function calculateCenter($point_list, $attr_num) { 

$vals = array(); 

$point_num = 0; 

 

$keys = array_keys($point_list[0]); 

foreach($keys as $value) 

$vals[$value] = 0; 

 

foreach ($point_list as $arr) 

$point_num++; 

foreach ($arr as $key => $value) 

$vals[$key] += $value; 

 

 

foreach ($keys as $index) 

$vals[$index] = $vals[$index] / $point_num; 

 

return $vals; 

 

 

 

function RGBToHex($r, $g=”, $b=”) 

if (is_array($r)) 

$b = $r['b']; 

$g = $r['g']; 


$r = $r['r']; 

 

$hex = “#”; 

$hex.= str_pad(dechex($r), 2, ’0′, STR_PAD_LEFT); 

$hex.= str_pad(dechex($g), 2, ’0′, STR_PAD_LEFT); 

$hex.= str_pad(dechex($b), 2, ’0′, STR_PAD_LEFT); 

 

return $hex; 

?> 

本文章来给各位同学介绍一个不错的需要登录的php 文件上传管理系统,功能简单有需要了解的同学可参考。
 代码如下 复制代码

<?php
$admin_pw="admin";//管理密码
$uploaddir="upload";//上传目录
session_start();
if($_GET['action']=="getcode")
{
  setcode();
  exit();
}
if($_POST['password']==$admin_pw && $_POST['yz']==$_SESSION['yzcode'])
{
  $_SESSION['logined']=$admin_pw;
}
if($_GET['action']=="logout")
{
  $_SESSION['logined']="";
  header("location: ".$_SERVER['PHP_SELF']);
  exit();
}
if($_SESSION['logined']!=$admin_pw)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>请登录</title>
</head>
<body>
<form action="" method="post">
输入密码:<input type="password" name="password" style="width:100px;" /><br />验证字符:<input type="text" style="width:40px;" name="yz" /><a href="#" onclick="document.tzm.src='?action=getcode';"><img src="?action=getcode" alt="验证码" id="tzm" name="tzm" /></a><br /><input type="submit" value="进入管理" />
</form>
</body>
</html>
<?php
}
else
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>文件上传</title>
</head>
<body>
<?php
  if($_POST['ac']=="upload")
  {
 $fileall=explode('.',$_FILES['file']['name']);
 $filetype=$fileall[count($fileall)-1];
 $filename=$uploaddir."/".$_FILES['file']['name']."_".rand(1,999999999).".".$filetype;
 $fileexists=file_exists($filename);
 while($fileexists==true)
 {
  $filename=$uploaddir."/".$_FILES['file']['name']."_".rand(1,999999999).".".$filetype;
  $fileexists=file_exists($filename);
 }
 if(move_uploaded_file($_FILES["file"]["tmp_name"],$filename))
 {
  $url="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  echo "文件:".$filename." 上传成功!<br>文件地址:<input type=text style='width:350px;' value=".dirname($url)."/".$filename." /><a href=".dirname($url)."/".$filename." target="_blank">测试</a>";
 }
 else
 {
  echo "文件".$filename."上传失败!";
 }
  }
?>
<form action="" method="post" enctype="multipart/form-data">
选择文件:<input type="file" name="file" id="file" width="100px" /><input type="hidden" name="ac" value="upload" /><input type="submit" value="上传" />
</form>
<p><a href="?action=logout">退出登录</a></p>
</body>
</html>
<?php
}


function setcode()
{
  Header("Content-type: image/gif");
  $border = 0; //是否要边框 1要:0不要
  $how = 4; //验证码位数
  $w = $how*15; //图片宽度
  $h = 20; //图片高度
  $fontsize = 5; //字体大小
  $alpha = "abcdefghijkmnopqrstuvwxyz"; //验证码内容1:字母
  $number = "0123456789"; //验证码内容2:数字
  $randcode = ""; //验证码字符串初始化
  srand((double)microtime()*1000000); //初始化随机数种子
  $im = ImageCreate($w, $h); //创建验证图片
  $bgcolor = ImageColorAllocate($im, 255, 255, 255); //设置背景颜色
  ImageFill($im, 0, 0, $bgcolor); //填充背景色
  if($border)
  {
    $black = ImageColorAllocate($im, 0, 0, 0); //设置边框颜色
    ImageRectangle($im, 0, 0, $w-1, $h-1, $black);//绘制边框
  }
  for($i=0; $i<$how; $i++)
  {  
    $alpha_or_number = mt_rand(0, 1); //字母还是数字
    $str = $alpha_or_number ? $alpha : $number;
    $which = mt_rand(0, strlen($str)-1); //取哪个字符
    $code = substr($str, $which, 1); //取字符
    $j = !$i ? 4 : $j+15; //绘字符位置
    $color3 = ImageColorAllocate($im, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100)); //字符随即颜色
    ImageChar($im, $fontsize, $j, 3, $code, $color3); //绘字符
    $randcode .= $code; //逐位加入验证码字符串
  }
  $_SESSION['yzcode'] = $randcode;
  Imagegif($im);
  ImageDestroy($im);
}
?>

[!--infotagslink--]

相关文章

  • php正确禁用eval函数与误区介绍

    eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
  • php中eval()函数操作数组的方法

    在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
  • Python astype(np.float)函数使用方法解析

    这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08
  • Python中的imread()函数用法说明

    这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
  • C# 中如何取绝对值函数

    本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
  • C#学习笔记- 随机函数Random()的用法详解

    下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • 金额阿拉伯数字转换为中文的自定义函数

    CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
  • Android开发中findViewById()函数用法与简化

    findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20
  • C++中 Sort函数详细解析

    这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
  • PHP用strstr()函数阻止垃圾评论(通过判断a标记)

    strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
  • PHP函数分享之curl方式取得数据、模拟登陆、POST数据

    废话不多说直接上代码复制代码 代码如下:/********************** curl 系列 ***********************///直接通过curl方式取得数据(包含POST、HEADER等)/* * $url: 如果非数组,则为http;如是数组,则为https * $header:...2014-06-07
  • php中的foreach函数的2种用法

    Foreach 函数(PHP4/PHP5)foreach 语法结构提供了遍历数组的简单方式。foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信息。...2013-09-28
  • C语言中free函数的使用详解

    free函数是释放之前某一次malloc函数申请的空间,而且只是释放空间,并不改变指针的值。下面我们就来详细探讨下...2020-04-25
  • PHP函数strip_tags的一个bug浅析

    PHP 函数 strip_tags 提供了从字符串中去除 HTML 和 PHP 标记的功能,该函数尝试返回给定的字符串 str 去除空字符、HTML 和 PHP 标记后的结果。由于 strip_tags() 无法实际验证 HTML,不完整或者破损标签将导致更多的数...2014-05-31
  • SQL Server中row_number函数的常见用法示例详解

    这篇文章主要给大家介绍了关于SQL Server中row_number函数的常见用法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-08
  • PHP加密解密函数详解

    分享一个PHP加密解密的函数,此函数实现了对部分变量值的加密的功能。 加密代码如下: /* *功能:对字符串进行加密处理 *参数一:需要加密的内容 *参数二:密钥 */ function passport_encrypt($str,$key){ //加密函数 srand(...2015-10-30
  • CI框架开发新浪微博登录接口源码完整版

    首先来看下流程:流程原理: 1.通过code获得access_token通过授权,并获取用户的信息(包括用户u_id)(这个u_id在后面的第三方登录表里面叫sina_id,那个表是需要自己建的) 2.查询第三方登录表,如果不存在用户sina_id,分2...2014-05-31
  • php的mail函数发送UTF-8编码中文邮件时标题乱码的解决办法

    最近遇到一个问题,就是在使用php的mail函数发送utf-8编码的中文邮件时标题出现乱码现象,而邮件正文却是正确的。最初以为是页面编码的问题,发现页面编码utf-8没有问题啊,找了半天原因,最后找到了问题所在。 1.使用 PEAR 的...2015-10-21
  • C#中加载dll并调用其函数的实现方法

    下面小编就为大家带来一篇C#中加载dll并调用其函数的实现方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • C#虚函数用法实例分析

    这篇文章主要介绍了C#虚函数用法,实例分析了C#中虚函数的功能与基本使用技巧,需要的朋友可以参考下...2020-06-25