php中g(shù)etservbyport與getservbyname函數(shù)用法實(shí)例
更新時(shí)間:2014年11月18日 14:31:01 投稿:shichen2014
這篇文章主要介紹了php中g(shù)etservbyport與getservbyname函數(shù)用法,以實(shí)例形式分析了getservbyport與getservbyname函數(shù)獲取server端的端口等信息的方法,需要的朋友可以參考下
本文實(shí)例講述了php中g(shù)etservbyport與getservbyname函數(shù)用法。分享給大家供大家參考。具體如下:
復(fù)制代碼 代碼如下:
string getservbyport ( int $port , string $protocol )
*/
$services=array('80','21','22','23','25','143'); //定義數(shù)組
foreach($services as $service) //循環(huán)讀取內(nèi)容
{
$protocol=getservbyport($service,'tcp'); //返回端口號對應(yīng)的協(xié)議
echo $service.":".$protocol."<br/>n"; //輸出結(jié)果
}
/*
int getservbyname ( string $service , string $protocol )
*/
$services=array('http','ftp','ssh','telnet','imap',
'smtp','nicname','gopher','finger','pop3','www'); //定義一個(gè)數(shù)組
foreach($services as $service) //循環(huán)讀取內(nèi)容
{
$port=getservbyname($service,'tcp'); //獲取數(shù)組元素對應(yīng)端口
echo $service.":".$port."<br/>n"; //輸出結(jié)果
}
希望本文所述對大家的php程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- php中的四舍五入函數(shù)代碼(floor函數(shù)、ceil函數(shù)、round與intval)
- PHP取整函數(shù):ceil,floor,round,intval的區(qū)別詳細(xì)解析
- php取整函數(shù)ceil,floo,round的用法及介紹
- php筆記之:php函數(shù)range() round()和list()的使用說明
- php使用function_exists判斷函數(shù)可用的方法
- php圖片處理函數(shù)獲取類型及擴(kuò)展名實(shí)例
- php常用的url處理函數(shù)總結(jié)
- PHP中常用的字符串格式化函數(shù)總結(jié)
- PHP中round()函數(shù)對浮點(diǎn)數(shù)進(jìn)行四舍五入的方法
相關(guān)文章
yii2項(xiàng)目實(shí)戰(zhàn)之restful api授權(quán)驗(yàn)證詳解
這篇文章主要給大家介紹了關(guān)于yii2項(xiàng)目實(shí)戰(zhàn)之restful api授權(quán)驗(yàn)證的相關(guān)資料,文中介紹的非常詳細(xì),對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。2017-05-05
php中file_get_contents()函數(shù)用法實(shí)例
在本文中我們給大家整理了關(guān)于php中file_get_contents()函數(shù)的相關(guān)用法,需要的朋友們學(xué)習(xí)參考下。2019-02-02
PHP實(shí)現(xiàn)二維數(shù)組中的查找算法小結(jié)
這篇文章主要介紹了PHP實(shí)現(xiàn)二維數(shù)組中的查找算法,涉及PHP數(shù)組遍歷、判斷、計(jì)算等相關(guān)操作技巧,需要的朋友可以參考下2018-06-06
Linux fgetcsv取得的數(shù)組元素為空字符串的解決方法
使用CSV導(dǎo)入數(shù)據(jù)的時(shí)候,我們通常用的是Windows系統(tǒng),使用GBK在Windows的Excel中編輯2011-11-11

