Time of Update: 2016-06-07
在PHP的官網上看到的parse_url()函數的替代方案。結果和parse_url()函數差不多,是使用正則實現的。URI 是 Web上可用的每種資源 - HTML文檔、映像、視頻片段、程式等 - 由一個通用資源標誌符(Uniform Resource Identifier, 簡稱"URI")進行定位。 對象分組:複製代碼 代碼如下:^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?12 3 4
Time of Update: 2016-06-07
複製代碼 代碼如下:/** * 網站地圖更新控制器 * * @author Garbin * @usage none */class SitemapApp extends FrontendApp{ function __construct() { $this->SitemapApp(); } function SitemapApp() { parent::__construct();
Time of Update: 2016-06-07
function getWeiboData(){ $count = 15; // 參數source後面輸入你的授權號 $url = "https://api.weibo.com/2/statuses/home_timeline.json?source=123456789&count=".$count."&page=1"; echo $url.''; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); //
Time of Update: 2016-06-07
得到一個xml型的對象:複製代碼 代碼如下:$resp = $this->c->execute($req,
Time of Update: 2016-06-07
下面的函數可以用來過濾使用者的輸入,保證輸入是XSS安全的。具體如何過濾,可以參看函數內部,也有注釋。複製代碼 代碼如下:function RemoveXSS($val) { // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed // this prevents some character re-spacing such as // note that you
Time of Update: 2016-06-07
複製代碼 代碼如下:$data = array( 'title'=>'ilsea', 'list'=>array( 'hello', 'world' ) );include('show.php');// show.php 模板檔案 echo $data['title']; echo ''; print_r($data['list']);
Time of Update: 2016-06-07
本機:複製代碼 代碼如下:$uri = "http://www.a.com/test.php";//這裡換成你伺服器的地址// 參數數組$data = array ( 'name' => 'tanteng' // 'password' => 'password');$ch = curl_init ();// print_r($ch);curl_setopt ( $ch, CURLOPT_URL, $uri );curl_setopt ( $ch, CURLOPT_POST, 1 );curl_
Time of Update: 2016-06-07
不多說,直接上代碼複製代碼 代碼如下://連結資料庫'查詢mysql_connect('localhost','username','userpwd')or die("資料庫連結失敗".mysql_error());mysql_select_db('庫名');mysql_query('set names utf8');$sql1="select * from user
Time of Update: 2016-06-07
檔案目錄:ipLocation-----qqwry----------QQWry.Dat-----ipCity.class.phpipCity.class.php檔案代碼:複製代碼 代碼如下:class ipCity { /** * 根據ip地址擷取對應所在城市 * @param type $userip 使用者IP地址 * @return string */ public function getCity( $userip, $dat_path =
Time of Update: 2016-06-07
遍曆目錄或遍曆目錄下指定類型的檔案,這是每一個童鞋在寫程式的時候難免會用到的。PHP本身也提供了很多灰常有用的函數,正確地使用它們,不會有錯滴。下面就我個人學習過程中的一些總結,希望對想學PHP的童鞋有所協助。本函數可以列出指定目錄下所有的檔案(包括子目錄下的)複製代碼 代碼如下:function getfiles($path){ foreach(scandir($path) as $afile){if($afile=='.'||$afile=='..') continue;
Time of Update: 2016-06-07
有的瀏覽器安裝了pdf開啟程式關聯到瀏覽器,所以直接寫上pdf路徑時是開啟pdf而不是下載,下面我就說下如果讓他們只是下載,而不是瀏覽。建立一個php檔案複製代碼 代碼如下:$file = $_GET['file'];$arr = explode('/',$file);header('Content-type: application/pdf');header('Content-Disposition: attachment;
Time of Update: 2016-06-07
經過兩天的Regex的學習,和研究wordpress的路由函數,成功實現了自訂wordpress路由功能,以下是路由規則的實現。如果有自訂的url參數,要通過路由傳遞,必須通過wordpress的函數將參數添加進去:複製代碼 代碼如下://add query_argsfunction add_query_vars($aVars) { $aVars[] = 'score'; $aVars[] = 'type'; // represents the name of the
Time of Update: 2016-06-07
假設叫數組 $my_array;複製代碼 代碼如下:// 建立一個空的數組.$tmp_array = array();$new_array = array();// 1. 迴圈出所有的行. ( $val 就是某個行)foreach($my_array as $k => $val){ $hash = md5(json_encode($val)); if (in_array($hash, $tmp_array)) { echo('這個行已經有過了'); }else{
Time of Update: 2016-06-07
一維數組的重複項:使用array_unique函數即可,使用執行個體如下:複製代碼 代碼如下: $aa=array("apple","banana","pear","apple","wail","watermalon"); $bb=array_unique($aa); print_r($bb); ?>結果如下:Array ( [0] =>
Time of Update: 2016-06-07
概述共用記憶體是一種在相同機器中的應用程式之間交換資料的有效方式。一個進程可建立一個可供其他進程訪問的記憶體段,只要它分配了正確的許可權。每個記憶體段擁有一個惟一的 ID(稱為 shmid),這個 ID 指向一個實體記憶體地區,其他進程可在該地區操作它。建立並提供了合適的許可權之後,同一台機器中的其他進程就可以操作這些記憶體段:讀取、寫入和刪除。這表明使用 C 語言編寫的應用程式可與使用其他語言(比如 Java™ 或
Time of Update: 2016-06-07
PHP中echo(),print(),print_r(),return的區別?往往有很多新手和不太使用print()的朋友就答不好這個問題 從而面試失敗。那麼究竟她們有什麼區別呢?下面我們來看看答案:echo是PHP語句, print和print_r是函數,語句沒有傳回值,函數可以有傳回值(即便沒有用)print() 只能列印出簡單類型變數的值(如int,string)print_r() 可以列印出複雜類型變數的值(如數組,對象)return 語句
Time of Update: 2016-06-07
本節內容:php函數指定預設值在php編程中,為自訂函數設定預設值,當使用者調用該函數時,如果不給參數指定值,參數會用預設值頂替。例1,複製代碼 代碼如下:php函數指定預設值-www.php.netfunction printMe($param = NULL){ print $param;}printMe("This is test");printMe();?>輸出結果:This is test例2,php函數參數預設值的使用範例,php函數參數中設定和使用預設值。代碼:複製代碼
Time of Update: 2016-06-07
PHP PDO Access連結複製代碼 代碼如下:class DbHelpClass { private $conn; private $qxId; private $ret; function __construct() { $path="../../App_Data/sd#f#45G_!.mdb"; $constr="DRIVER={Microsoft Access
Time of Update: 2016-06-07
如:時間剛好是5分鐘前,則對應的時間戳記就會被格式化為5分鐘前,不多說了,直接貼上代碼: 複製代碼 代碼如下: /** * 格式化時間 * @param integer $timestamp 時間戳記 * @param string $format dt=日期時間 d=日期 t=時間 u=個人化 其他=自訂 * @param integer $timeoffset 時區值 * @param string $custom_format 自訂時間格式 * @return string */
Time of Update: 2016-06-07
本文介紹下,php中使用array_multisort函數進行二維數組排序的例子,有需要的朋友,參考下吧。繼上一篇文章:PHP二維數組排序自訂函數,今天,我們再介紹一個php二維數組排序的例子。php對二維數組的排序很簡單,主要用到array_multisort函數。例子:複製代碼 代碼如下:/** * php二維數組排序 * edit www.php.net*/ $data = array(); $data[] = array('volume' => 67, 'edition'