html代碼中的form參數是基本一致的

來源:互聯網
上載者:User

標籤:自動   sql   dtd   安全   路徑   ima   username   trie   返回   

由於pear的大多數模組仍處於開發當中,因此,這裡列舉的是隨著php4.05一起發布的pear中的模組,需要注意的是,一些抽象類別或者是基類(如mail.php,log.php,cache.php)沒有列舉出來,我們只是關注具有具體功能的模組。下面是這些模組的一個列表: 

benchmark/timer 測試你的一段php代碼的運行效率 
benchmark/benchmark_iterate 測試你某個函數迴圈執行時的效能 
cache/output 可以將你的php指令碼的輸出進行緩衝,可以使用多種方式緩衝(存在檔案,資料庫或者是共用記憶體中),如果使用這個模組有可能增大伺服器的負載,所以,如果你想通過動態指令碼的緩衝來提供效率,不妨使用zend optimize,這個模組未必適合 
cache/graphics 可以將你需要動態輸出的圖片進行緩衝 
console/getopt 命令列參數的處理模組 
cmd 一個虛擬shell,可以用它來運行一些系統的命令 
crypt/cbc 實現perl crypt::cbc 模組的模擬 
crypt/hcemd5 實現perl crypt::hce_md5 模組的功能 

date/calc 實現日期的相關操作 
date/human human曆法的轉換 
db 提供統一的、抽象的資料庫操作層,後端支援多種資料庫 
file/find 檔案尋找 
file/passwd 操縱password類的檔案,如password,httppass,cvspassword 
file/searchreplace 在檔案中尋找替換字串 
html/form 可以在html中快速地建立form 
html/it 實現模板定製,動態產生頁面的功能,類似phplib中的模板功能,但是要簡單易用 
html/itx 實現對it的擴充功能,可以更加靈活地定製你的模板,實現更複雜的操作 
html/processor xml_parser的擴充,使之可以應用於html檔案的操作 
http/compress 用於php 輸出緩衝機制的一個封裝類,同時可以對緩衝的內容進行壓縮儲存 
image/remote 無需把整個圖片都下載到本地就可以擷取遠端系統的圖片的資訊, 
log/composite horde對log抽象類別做的一個擴充,可以使多個Tlog對象能夠獲得同一個日誌事件。注意,log目錄下面的模組都是horde項目的一部分,大部分都是抽象的超類 
log/file 將日誌資訊寫入檔案 
log/mcal 將資訊發送到本地或遠端的議程管理軟體-mcal的資料庫中 
log/observer horder中observer的一個超類 
log/sql 將日誌資訊發送到sql資料庫中 
log/syslog 將資訊發送到syslog中 
mail/rfc822 檢查一個email地址是否是合法的rf822 email地址 
mail/sendmail 使用sendmail來發送信件 
mail/smtp 使用smtp伺服器來發送信件 
math/fraction 處理分形的數學計算 
math/util 計算最大公約數 
net/curl 對php的curl擴充所作的物件導向的封裝 
net/dig 操縱dig,進行dns相關的查詢操作 
net/smtp 使用net/socket實現smtp協議 
net/socket 通用的socket類,實現了常用的socket操作的封裝 
numbers/roman 阿拉伯數字和羅馬數位相互轉換 
payment/verisign 實現和verisign支付網關的互動 
pear 提供pear模組的2個基本類,pear 和pearerror類 
pear/installer pear的安裝類,提供perl中的cpan模組類似的功能 
phpdoc 從php代碼中自動產生api文檔 
schedule/at 和unix 上的at守護進程進行互動 
xml/parser 基於php的xml擴充所作的xml的解析器 
xml/render 將xml文檔產生其它的格式(html,pdf),這隻是一個抽象類別,在最新的pear cvs代碼中已經有了html的實現 
xml/rpc 用php實現xml-rpc的一個抽象類別,在最新的pear cvs代碼中已經有了xml/rpc/server的實現

三、主要模組使用簡介 
現在我們將簡單地介紹一些比較常用的,而且功能已經比較完善和穩定,可以用於“實戰“模組,其中對於幾個功能很強大的模組db,phpdoc,xml_parser,it,itx將在以後的文章中單獨介紹。 

1.pear/installer 
這個模組屬於pear本身的核心模組,它完成pear其它模組的安裝和維護工作,類似perl中的cpan模組的功能,不過目前只有install功能,其它諸如查詢,檢查依賴性等等都沒有完成,pear本身也沒有類似 cpan 那樣的開放的網站,不過隨著參與pear的開發人員的不斷增加,一切都會有的。 

使用文法:pear_installer::installer($file) 
$file是需要安裝的模組檔案,可以是本地檔案,也可以是遠端檔案,如http://或者是ftp,installer會自動下載到本地。檔案一般使用gzip打包,其中要包括一個package.xml檔案,用於描述你的這個模組的相關資訊,如包含的檔案,相互依賴性等,此外當然要包括你的模組的php檔案。pacakage.xml的dtd檔案在pear目錄下面,名字是package.dtd. 

<?php 
require_once "pear/installer.php"; 
$installer = new pear_installer; 
//安裝指定的模組 
$result = $installer->install($package_file); 
if ( pear::iserror($result)){ 
echo "install $package_file failed!"; 
}else { 
echo "install $package_file sucess!"; 

?> 

2.cmd 
雖然大多數的php應用很少調用系統命令,因為這些應用都是基於web的,從運行效率和系統的負載考慮,都要避免直接調用系統命令,不過,在有些特殊的應用或者是你願意把php作為一個shell工具的時候,調用現有的系統工具就是不可避免的了。cmd可以讓你很方便地執行一系列的系統命令。 

使用文法:setoption ($option, $setting) 
設定參數$options為$setting 

$options是一個常量,它可以是以下值: 
cmd_shutdown : 通過shutdown函數來執行命令 
cmd_shell : 指定shell的路徑 
cmd_output : 是否屏蔽命令的標準輸出 
cmd_nohup : 使用nohup後台執行命令 
cmd_verbose : 將錯誤列印到標準輸出 

command($command) 
添加需要執行的命令,$command可以是數組或普通的字串 

exec() 
執行已經添加的命令 

<?php 
require_once "cmd.php"; 
$cmd = new cmd; 
$cmd->command(tar zcvf test.tar.gz ~/test); 
if ( $cmd->exec() ) { 
echo "success!\n"; 
} esle { 
echo "error:" . $cmd->lasterror; 

?> 

3.benchmark/timer和benchmark/iterate 
這2個模組可以讓你測試你的代碼的運行效率如何,我認為這對於系統調試很有用:你可以嘗試不同的演算法,仔細考察每種演算法需要啟動並執行時間,然後選擇最佳的方式。benchmark/timer測試回合中在2個不同的時間點的時間差,benchmark/iterate則是對timer擴充,測試回合某段代碼(函數)n次所需要的時間。 

使用文法:benchmark/timer 

timer::setmarker($name) 設定目前時間點為$name 
timer::start() 開始測試 
timer::stop() 停止測試 
timer::timeelapsed($start = start, $end = stop) 計算$start和$end 這2個時間點的時間差 
timer::getprofiling() 返回start 和 stop 之間所耗用的時間 
<?php 
require_once "benchmark/timer.php"; 
$timer = new benchmark_timer; 

$timer->start(); 
$timer->setmarker(marker 1); 
$timer->stop(); 

$profiling = $timer->getprofiling(); 
?> 
benchmark/iterate 

iterate::run() 
迴圈運行指定的函數。這是一個具有可變參數的方法,第一個參數是要迴圈的次數,第2個參數是要執行的函數,第3個參數起則是要傳遞給測試函數的參數。 

iterate::get() 
返回測試所用的時間 

<?php 
require_once "benchmark/iterate.php"; 

$benchmark = new benchmark_iterate; 

function foo($string) 

print $string." 
"; 

$benchmark->run(100, foo, test); 
$result = $benchmark->get(); 
?> 

3.file/find 
&glob ($pattern, $dirpath, $pattern_type=php) 
在$dirpath中搜尋符合$pattern的目錄和檔案,返回匹配的檔案和目錄名數組 

&search ($pattern, $directory, $type=php) 
在$directory中搜尋符合$pattern規則的檔案,返回匹配的檔案名稱數組(注意,只是檔案,不包括子目錄)。$pattern是要指定的搜尋條件,一般是規則運算式,$patten_type指定使用什麼模式的規則運算式,預設是php模式,你也可以指定"perl"來使用perl模式的規則運算式 

提示:search和glob不同的是,glob並不遞迴搜尋子目錄,而search則遞迴搜尋子目錄。 

<?php 
require_once "file/find.php"; 
$find = new file_find; 
//搜尋目前的目錄 
$php_files = $find->glob("*php","."); 
if ( pear::iserror( $php_files ) ){ 
die "錯誤:" . $php_files->getmessage() ."\n" ; 

//遞迴搜尋目前的目錄 
$all_php_files = $find->search("*php","."); 
if ( pear::iserror( $all_php_files ) ){ 
die "錯誤:" . $php_files->getmessage() ."\n" ; 

?> 

4.file/passwd 
操縱password格式的檔案,類似如標準的unix password,apache 的.htppass,cvs的pserver password檔案。從現有版本的代碼來看,它還不能真正地用來維護這些passwd檔案(比如並不支援shadow)。不過你可以用來建立類似的密碼檔案,當然,安全性不會很高。 

使用方法: 
file_passwd($file,$lock=0)----------建立對象,$file是你要操作的passwd檔案,$lock指定是否要用flock對檔案上鎖。 
adduser($user,$pass,$cvsuser)----------增加一個使用者,$user,$pass分別是使用者名稱和密碼,$cvsuser是cvs 使用者的id 
moduser($user,$pass,$cvsuser)----------修改$user的密碼為$pass,$cvsuser是cvs 使用者的id 
deluser($user)----------刪除指定的使用者$user 
verifypassword($user,$pass)----------檢驗使用者密碼 
close()----------儲存剛才的修改到password檔案,關閉password檔案,對檔案解鎖。 
5.file/searchreplace 
在檔案中尋找和替換字串 

使用方法:file_searchreplace($find, $replace, $files, $directories = , $include_subdir = 1, $ignore_lines = array()) 

產生並設定對象 

$find 
要尋找的字串,可以是字串或規則運算式 

$replace 
要替換成的字串,可以是字串或規則運算式 

$files 
指定在哪些檔案中進行替換操作,數組或者是以","分割的一個字串 

$directories 
指定在那個目錄中操作,可選,數組或者是以","分割的一個字串 

$include_subdir 
如果是在目錄中操作,指定是否在子目錄中遞迴執行上述操作,可以是數值1或0。 

$ignore_lines 
指定要忽略的檔案行,這是一個數組,任何以這個數組中任意一個字串開始的檔案行,都會忽略。

getnumoccurences() 
返回已經執行了尋找替換的次數 

getlasterror() 
返回上一次的錯誤資訊 

setfind($find) 
設定要尋找的字串 

setreplace($replace) 
設定要替換的字串 

setfiles($files) 
設定要執行替換操作的檔案 

setdirectories($directories) 
設定要替換操作的目錄 

setincludesubdir($include_subdir) 
設定是否在子目錄中也執行尋找替換 

setignorelines($ignore_lines) 
設定要忽略的行,只能在使用"normal"搜尋函數的時候使用 

setsearchfunction($search_function) 
設定要使用的搜尋函數,可以是下列參數: 

normal 預設值,使用file函數讀入檔案內容,然後使用str_replace逐行的進行替換。 
quick 使用str_replace直接對整個檔案進行替換 
preg 使用preg_replace()來進行替換,你可以使用符合這個函數要求的規則運算式 
ereg 使用ereg_replace()來進行替換,你可以使用符合這個函數要求的規則運算式 



dosearch() 
執行尋找替換操作 

<?php 
require_once "file/searchreplace.php"; 
require_once "file/find"; 

//遞迴搜尋目前的目錄 
$find = new file_find; 
$all_php_files = $find->search("*php","."); 
if ( pear::iserror( $all_php_files ) ){ 
die "錯誤:" . $php_files->getmessage() ."\n" ; 

if ( !count($all_php_file) ){ 
die "no php source files found!\n"; 

//將<?的php標誌修正成<?php,以符合pear標準 
$replace = new file_searchreplace(<? ,<?php ,$all_php_files); 
$replace->dosearch(); 
if ( $replace->getlasterror() ) { 
die "發生錯誤:" . $replace->getlasterror() ; 
} else { 
echo "共成功替換了 " . $replace->getnumoccurences() . " 處。\n"; 

?> 

6.html/form 
這個模組可以讓你快速地產生一個提交的表單,而無需重新去編寫html代碼 

使用方法:form::html_form($action, $method = get, $name = , $target = ) 

這個類的建構函式帶有一些參數,這些參數和通常要編寫html代碼中的form參數是基本一致的,$action是在form中要提交到的url,$name可以指定form的名字,$target指定是否要新開視窗等等。 

下面的addxxx系列方法,用於在這個form中添加相應的控制項,控制項的屬性和html中的也相一致。 
addtext($name, $title, $default, $size = html_form_text_size) 
addcheckbox($name, $title, $default) 
addtextarea($name, $title, $default,$width = html_form_textarea_wt,$height = html_form_textarea_ht) 
addpassword($name, $title, $default, $size = html_form_passwd_size) 
addsubmit($name = "submit", $title = "submit changes") 
addreset($title = "discard changes") 
addselect($name, $title, $entries, $default = , $size = 1,$blank = , $multiple = false, $attribs = ) 
addradio($name, $title, $value, $default) 
addimage($name, $src) 
addhidden($name, $value) 

display() 
顯示這個表單 

<?php 
require_once "html/form.php"; 
//建立並顯示登入表單 
$myform = new html_form("./login.php"); 
$myform->addtext(username,使用者名稱,); 
$myform->addpasswd(passwd,登入密碼,20); 
$myform->addhidden(retry,1); 
$myform->addsumit(login,登入); 
$myform->display(); 
?> 

7.mail/rfc2881064151 
檢查一個輸入的email是否合法,不是一件很輕鬆的事情,你也許嘗試使用一些規則運算式來檢查,但是並非那麼方便有效。現在,如果要檢查一系列的郵件地址是否符合rfc822標準,並把它們拆分成單獨的email地址,你可以試試這個模組,非常簡單實用。 

使用方法:mail_rfc822($address = null, $default_domain = null, $nest_groups = null, $validate = null) 

類建構函式,$address是你要驗證的一系列的地址,$default_domain,指定預設的網域名稱或者主機名稱,$nest_groups 是否在輸出結果中進行分組,以便顯示$validate 是否需要驗證每個原子parseaddresslist($address = null, $default_domain = null, $nest_groups = null, $validate = null)分析驗證所給定的地址清單,如果地址有效,返回拆分後的單獨的地址清單,如果發生錯誤,則返回錯誤資訊。 

<?php 
require_once "mail/rfc822.php"; 
$rf822 = new mail_rfc822; 
$result=$rf822->paseaddresslist(who;[email protected];[email protected]); 
if ( $rf822->error ){ 
echo "error:$result"; 
}else { 
reset($result); 
for ($i=0; $i< count($result);$i++){ 
echo "email:$result[$i]\n"; 


?> 

8.mail/sendmail 
sendmail是unix/linux上面最常用的mta,這個模組可以讓你直接使用sendmail來發送信件 

html代碼中的form參數是基本一致的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.