php

获取文件扩展名

<?php
header ( "Content-Type: text/html; charset=UTF-8" );
// function get_extension($filename){
// return substr(strrchr($filename,"."),1);
// }


// function get_extension($filename){
// return substr($filename,strrpos($filename,".")+1);
// }


// function get_extension($filename){
// $filearray=explode(".",$filename);
// return end($filearray);
// }


function get_extension($filename){
return $fileinfo=pathinfo($filename,PATHINFO_EXTENSION);
}

//....
02
        $tempfile = @fopen($img, "rb");
03
        $bin= fread($tempfile, 2); //只读2字节 
04
        fclose($tempfile);
05
        $strInfo = @unpack("C2chars", $bin);
06
        $typeCode = intval($strInfo['chars1'] . $strInfo['chars2']);
07
        $fileType = '';
08
        switch($typeCode){ // 6677:bmp 255216:jpg 7173:gif 13780:png 7790:exe 8297:rar 8075:zip tar:109121 7z:55122 gz 31139
09
            case '255216':
10
                $fileType = 'jpg';
11
                break;
12
            case '7173':
13
                $fileType = 'gif';
14
                break;
15
            case '13780':
16
                $fileType = 'png';
17
                break;
18
            default:
19
                $fileType = 'unknown';
20
        }
21
//....
echo get_extension("uolpad.php");
?>

 

$filename='index.php';
echo substr(strrchr($filename,'.'),1);
echo substr($filename,strpos($filename,'.')+1);
$filearr=explode('.',$filename);
echo end($filearr);
echo pathinfo($filename,PATHINFO_EXTENSION);

 $a='/a/b/c/d/e.php';
 $b='/a/b/12/34/c.php';
 function getRelativePath($a,$b){
 $a2array=explode('/',$a);
 $b2array=explode('/',$b);
 $pathinfo='';
 for($i=1;$i<=count($b2array)-2;$i++){
 $pathinfo.=$b2array[$i]==$a2array[$i]?'../':$b2array[$i].'/';
 }
 return $pathinfo;
 }
 echo getRelativePath($a,$b);

 function getFileTree($file){
 $tree=array();
 foreach(glob($file.'/*') as $single){
 if(is_dir($single)){
 $tree=array_merge($tree,getFileTree($single));
 }else{
 $tree[]=$single;
 }
 }
 return $tree;
 }
 print_r(getFileTree('F:/ECShop_V2.7.3_UTF8_release0411'));

 function getMaxNum($a,$b,$c){
 return ($a>$b)?(($a>$c)?$a:$b):(($b>$c)?$b:$c);
 }
echo getMaxNum(3,6,1);

echo strip_tags("Hello <b><i>world!</i></b>","<b>");

$a = 1; $b = $a;
unset($a);//$b是否还是1,为什么?
//unset($b);//$a是否还是1,为什么?
echo $b;
exit;

 

实现中文字符串截取的PHP实现方法
用最少的代码写一个求三个数最大值的函数
php如何取得当前运行脚本所在的文档目录
请用正则表达式写一个函数验证电子邮件的模式是否正确
使用三种以上的方式获取文件扩展名
求两个日期的差数,例如2007-2-5到2007-3-6的日期差数
echo count("abc") 结果是1.count()函数对于数组,返回其元素的个数,对于其它值,返回1.
开发过程中用什么方法来加快页面的加载速度?答:要用到服务器资源时才打开,及时关闭服务器资源,建立数据库索引,页面生成静态,图片等大文件单独存储服务器,代码优化工具。

PHP面向对象中__set()与__toString()的作用。http://www.cnblogs.com/glory-jzx/archive/2012/05/23/2514173.html
常见的http协议及提示代表什么意思?http://blog.sina.com.cn/s/blog_4ea497b70100tlq4.html

网络协议有哪些?TCP/IP,FTP,HTTP

php性能优化策略有哪些?http://www.jb51.net/article/24248.htm

 

// 用二分法(也叫折半查找法)查找某元素,对像可以是有序数组。
//二分法查找一个数组中是否存在某值
function binSearchWithArray($array,$searchValue){
 global $time;
 if(count($array)>=1){
  $mid = intval(count($array)/2);
 
  echo '第',$time++,'次<br/>';
  echo '当前数组:';print_r($array);echo '<br/>';
 
  echo '查找位置索引:',$mid,'<br/>';
  echo '值:',$array[$mid],'<br/><br/>';

  if($searchValue == $array[$mid]){
   $time--;
   return $searchValue.'被找到了,于第'.$time.'次,索引为'.$mid.'<br/>';
  }
  elseif($searchValue < $array[$mid]){
   $array = array_slice($array,0,$mid);
   return binSearchWithArray($array,$searchValue);
  }
  else{
   $array = array_slice($array,$mid+1,count($array));
   return binSearchWithArray($array,$searchValue);
  }
 }

 return $searchValue.'没找到<br/>';
}

$time = 1;
//要查找的数组
$array = array(1,5,8,101,13,19,25,50,60,199,35);
//要查找的值
$searchValue = 13;
//对数组排序,二分法的关键
sort($array);
echo '要查找的值为:',$searchValue,'<br/><br/>';
echo binSearchWithArray($array,$searchValue);

http协议请求头

 

转载于:https://www.cnblogs.com/happydd/p/3777962.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值