奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

php語言

PHP中常用的實例介紹

時間:2025-04-15 02:58:09 php語言 我要投稿
  • 相關推薦

PHP中常用的實例介紹

  PHP 獨特的語法混合了C、Java、Perl以及PHP自創的語法。它可以比CGI或者Perl更快速地執行動態網頁。下面小編給大家介紹PHP中常用的實例,歡迎閱讀!

  PHP中常用的實例介紹

  1.php解析url并得到url中的參數

  <?php

  $url = 'http://wwwXXX.com';

  $arr = parse_url($url);

  var_dump($arr);

  $arr_query = convertUrlQuery($arr['query']);

  var_dump($arr_query);

  var_dump(getUrlQuery($arr_query));

  /**

  * 將字符串參數變為數組

  * @param $query

  * @return array array (size=10)

  'm' => string 'content' (length=7)

  'c' => string 'index' (length=5)

  'a' => string 'lists' (length=5)

  'catid' => string '6' (length=1)

  'area' => string '0' (length=1)

  'author' => string '0' (length=1)

  'h' => string '0' (length=1)

  'region' => string '0' (length=1)

  's' => string '1' (length=1)

  'page' => string '1' (length=1)

  */

  function convertUrlQuery($query)

  {

  $queryParts = explode('&', $query);

  $params = array();

  foreach ($queryParts as $param) {

  $item = explode('=', $param);

  $params[$item[0]] = $item[1];

  }

  return $params;

  }

  /**

  * 將參數變為字符串

  * @param $array_query

  * @return string string 'm=content&c=index&a=lists&catid=6&area=0&author=0&h=0&region=0&s=1&page=1' (length=73)

  */

  function getUrlQuery($array_query)

  {

  $tmp = array();

  foreach($array_query as $k=>$param)

  {

  $tmp[] = $k.'='.$param;

  }

  $params = implode('&',$tmp);

  return $params;

  }

  2,利用正則表達式實現手機號碼中間4位用星號(*)替換顯示

  <?php

  //Method 1:

  function hidtel($phone){

  $IsWhat = preg_match('/(0[0-9]{2,3}[-]?[2-9][0-9]{6,7}[-]?[0-9]?)/i',$phone); //固定電話

  if($IsWhat == 1){

  return preg_replace('/(0[0-9]{2,3}[-]?[2-9])[0-9]{3,4}([0-9]{3}[-]?[0-9]?)/i','$1****$2',$phone);

  }else{

  return  preg_replace('/(1[358]{1}[0-9])[0-9]{4}([0-9]{4})/i','$1****$2',$phone);

  }

  }

  //Method 2:

  $num = "13966778888"

  $str = substr_replace($num,'****',3,4);

  //實例:

  $phonenum = "13966778888";

  echo hidtel($phonenum);

  //最后輸出:139****8888

  3.php根據出生年月日計算生日 精確到xxxx年xx月xx天

  <?php

  function diffDate($date1,$date2){

  $datestart= date('Y-m-d',strtotime($date1));

  if(strtotime($datestart)>strtotime($date2)){

  $tmp=$date2;

  $date2=$datestart;

  $datestart=$tmp;

  }

  list($Y1,$m1,$d1)=explode('-',$datestart);

  list($Y2,$m2,$d2)=explode('-',$date2);

  $Y=$Y2-$Y1; // 1

  $m=$m2-$m1; // 0

  $d=$d2-$d1; // -11

  if($d<0){

  $d+=(int)date('t',strtotime("-1 month $date2"));

  $m=$m--;

  }

  if($m<0){

  $m+=12;

  $y=$y--;

  }

  if($Y == 0 && $m == 0 && $d != 0){

  return $d.'天';

  }elseif($Y == 0 && $m != 0 && $d != 0){

  return $m.'個月'.$d.'天';

  }elseif($Y != 0 && $m == 0 && $d != 0){

  return $Y.'年'.$d.'天';

  }else{

  return $Y.'年'.$m.'個月'.$d.'天';

  }

  }

  4.php判斷手機瀏覽還是web瀏覽

  <?php

  function isMobile(){

  $useragent=isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';

  $useragent_commentsblock=preg_match('|(.*?)|',$useragent,$matches)>0?$matches[0]:'';

  function CheckSubstrs($substrs,$text){

  foreach($substrs as $substr)

  if(false!==strpos($text,$substr)){

  return true;

  }

  return false;

  }

  $mobile_os_list=array('Google Wireless Transcoder','Windows CE','WindowsCE','Symbian','Android','armv6l','armv5','Mobile','CentOS','mowser','AvantGo','Opera Mobi','J2ME/MIDP','Smartphone','Go.Web','Palm','iPAQ');

  $mobile_token_list=array('Profile/MIDP','Configuration/CLDC-','160×160','176×220','240×240','240×320','320×240','UP.Browser','UP.Link','SymbianOS','PalmOS','PocketPC','SonyEricsson','Nokia','BlackBerry','Vodafone','BenQ','Novarra-Vision','Iris','NetFront','HTC_','Xda_','SAMSUNG-SGH','Wapaka','DoCoMo','iPhone','iPod');

  $found_mobile=CheckSubstrs($mobile_os_list,$useragent_commentsblock) ||

  CheckSubstrs($mobile_token_list,$useragent);

  if ($found_mobile){

  return true;

  }else{

  return false;

  }

  }

  if (isMobile()){

  header('location: ./app/index.php');//如果為手機端,執行跳轉

  }

  else{

  header('location: ./web/index.php');//如果非手機端,執行跳轉

  }

  5.時間戳轉時間格式,時間格式轉xx小時前

  <?php

  /**

  * 將時間轉換為 xx小時前

  * @param {Object} pTime

  */

  function jsDateDiff(pTime) {

  var d_minutes, d_hours, d_days, d;

  var timeNow = parseInt(new Date().getTime() / 1000);

  pTime_new = new Date(pTime).getTime() / 1000;

  d = timeNow - pTime_new;

  d_days = parseInt(d / 86400);

  d_hours = parseInt(d / 3600);

  d_minutes = parseInt(d / 60);

  if (d_days > 0 && d_days < 4) {

  return d_days + "天前";

  } else if (d_days <= 0 && d_hours > 0) {

  return d_hours + "小時前";

  } else if (d_hours <= 0 && d_minutes > 0) {

  return d_minutes + "分鐘前";

  } else {

  return pTime;

  }

  }


【PHP中常用的實例介紹】相關文章:

php中fsockopen用法實例06-20

PHP中數組的分組排序實例11-14

php中return的用法實例分析10-27

php中實現回刪功能實例10-03

PHP中檢測ajax請求的代碼實例10-25

php畫圖實例07-16

php中try catch捕獲異常實例詳解07-29

php中curl模擬post請求小實例06-01

php常用的驗證類以及正則實例08-27

主站蜘蛛池模板: 庆城县| 合肥市| 原平市| 钟祥市| 民乐县| 赣州市| 乌拉特前旗| 科尔| 栾川县| 乌恰县| 凌源市| 湖南省| 呼图壁县| 明水县| 金溪县| 隆德县| 正蓝旗| 炉霍县| 中宁县| 临桂县| 贵定县| 莱阳市| 乌兰察布市| 昌平区| 泰来县| 梅河口市| 精河县| 花莲县| 湄潭县| 岑巩县| 瓮安县| 南平市| 云霄县| 麻阳| 湘潭市| 和龙市| 长葛市| 张家界市| 宁明县| 滨州市| 大洼县|