sina微博api源码阅读之函数
1. array_map將類的靜態(tài)成員函數(shù)作為回調(diào)函數(shù)用在指定的單元上,可以遞歸調(diào)用
public static function urlencode_rfc3986($input) {
??????? if (is_array($input)) {
??????????? return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input);
??????? } else if (is_scalar($input)) {
??????????? return str_replace(
??????????????? '+',
??????????????? ' ',
??????????????? str_replace('%7E', '~', rawurlencode($input))
??????????? );
??????? } else {
??????????? return '';
??????? }
??? }
關(guān)于類內(nèi)靜態(tài)回調(diào):
寫成array_map('OAuthUtil::urlencode_rfc3986', $input);
or array_map(array(__CLASS__, 'urlencode_rfc3986'), $input);
or array(__CLASS__, __METHOD__) 都是可以的,但是方法必須是static方法。
__CLASS__, __METHOD__是當(dāng)前類名和方法名的魔術(shù)常量,同__line__。
在這里用$this or self都是不可以的??梢詫慺oreach循環(huán),然后用self::urlencode_rfc3986方法。
如果是非static成員變量,array_map(array($this,'urltranscode'), $value);
$this是對象的引用,實例化時確定的。
self指向類本身,與實例化對象無關(guān),用來調(diào)用一些靜態(tài)變量和函數(shù)。
?
2. php輸入流
參照http://blog.haohtml.com/index.php/archives/5125
php://input可以讀取沒有處理過的POST數(shù)據(jù)。相較于$HTTP_RAW_POST_DATA而言,它給內(nèi)存帶來的壓力較小,并且不需要特殊的php.ini設(shè)置。php://input不能用于enctype=multipart/form-data
<?php
//@file phpinput_post.php
$http_entity_body = 'n=' . urldecode('perfgeeks') . '&p=' . urldecode('7788');
$http_entity_type = 'application/x-www-form-urlencoded';
$http_entity_length = strlen($http_entity_body);
$host = '192.168.0.6';
$port = 80;
$path = '/phpinput_server.php';
$fp = fsockopen($host, $port, $error_no, $error_desc, 30);
if ($fp) {
fputs($fp, "POST {$path} HTTP/1.1\r\n");
fputs($fp, "Host: {$host}\r\n");
fputs($fp, "Content-Type: {$http_entity_type}\r\n");
fputs($fp, "Content-Length: {$http_entity_length}\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $http_entity_body . "\r\n\r\n");
while (!feof($fp)) {
$d .= fgets($fp, 4096);
}
fclose($fp);
echo $d;
}
?>
在server端,可以通過一下函數(shù)獲取post的數(shù)據(jù)
$raw_post_data = file_get_contents('php://input', 'r');
1,Coentent-Type僅在取值為application/x-www-data-urlencoded和multipart/form-data兩種情況下,PHP才會將http請求數(shù)據(jù)包中相應(yīng)的數(shù)據(jù)填入全局變量$_POST
2,PHP不能識別的Content-Type類型的時候,會將http請求包中相應(yīng)的數(shù)據(jù)填入變量$HTTP_RAW_POST_DATA
3, ?只有Content-Type不為multipart/form-data的時候,PHP不會將http請求數(shù)據(jù)包中的相應(yīng)數(shù)據(jù)填入php://input,否則其它情況都會。填入的長度,由Coentent-Length指定。
4,只有Content-Type為application/x-www-data-urlencoded時,php://input數(shù)據(jù)才跟$_POST數(shù)據(jù)相一致。
5,php://input數(shù)據(jù)總是跟$HTTP_RAW_POST_DATA相同,但是php://input比$HTTP_RAW_POST_DATA更湊效,且不需要特殊設(shè)置php.ini
6,PHP會將PATH字段的query_path部分,填入全局變量$_GET。通常情況下,GET方法提交的http請求,body為空。
轉(zhuǎn)載于:https://www.cnblogs.com/hayley/archive/2011/01/18/1938029.html
總結(jié)
以上是生活随笔為你收集整理的sina微博api源码阅读之函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 去除iphone图标的半弧高亮效果
- 下一篇: 烟雨江湖心音流刀术怎么触发?