【php判断不为空】教程文章相关的互联网学习教程文章

php判断数组是否有序的示例代码

<?php/*** 判断数组是否有序* by bbs.it-home.org*/function JudegSortArray($array) { if ($array [0] > $array [1]) { $flag = 1; } else { $flag = 0; } $temp = $flag; $len = count ( $array ); for($i = 1; $i < $len; $i ++) { if ($flag == 0) { if ($array [$i] < $array [$i + 1]) { continue; }...

php根据日期判断星座的函数代码

<?phpfunction yige_constellation($month, $day) { // 检查参数有效性 if ($month < 1 || $month > 12 || $day < 1 || $day > 31) return false; // 星座名称以及开始日期 $constellations = array( array( "20" => "宝瓶座"), array( "19" => "双鱼座"), array( "21" => "白羊座"), array( "20" => "金牛座"), array( "21" => "双子座"), array( "22" => "巨蟹座"), array( "23" => "狮子座"), array( "23" => "处女座"...

php判断字符串是否全是中文或含有中文

<?php$str="324是"; if(!eregi("[^\x80-\xff]","$str")){ echo "全是中文"; }else{ echo "不是"; }二,判断含有中文 <?php$str = "中文"; if (preg_match("/[\x7f-\xff]/", $str)) { echo "含有中文"; }else{ echo "没有中文"; } 或 $pattern = /[^\x00-\x80]/; if(preg_match($pattern,$str)){ echo "含有中文"; }else{ echo "没有中文"; }说明: 以上代码在utf-8下面测试的,别的编码下没有测试过。

PHP取二进制文件头判断文件类型

/*** PHP取二进制文件头快速判断文件类型** @param 文件 $file* @return string* @author lrenwang* @blog blog.lrenwang.com*/function get_extname($file){ $fp = fopen($file, "rb"); $bin = fread($fp, 2); //只读2字节 fclose($fp); $bin_info = @unpack("C2chars", $bin); $code = intval($bin_info['chars1'].$bin_info['chars2']); switch ($code) { case 7790: $type = 'exe'; break; case 778...

php中文编码判断代码

preg_replace(”/([\x80-\xff])/”,”",$str); preg_replace(”/([u4e00-u9fa5])/”,”",$str);例子,php中文编码判断。<?php//判断内容里有没有中文-gbk (php) function check_is_chinese($s){ return preg_match(/[\x80-\xff]./, $s); } //获取字符串长度-gbk (php) function gb_strlen($str){ $count = 0; for($i=0; $i<strlen($str); $i++){ $s = substr($str, $i, 1); if (preg_match("/[\x80-\xff]/", $s)) ++$i; ++$count; ...

php判断文章中是否有图片简单示例

$url="http://XXXXX/article/012.html";  $content=file_get_contents($url); //读取文章页面源代码  if(preg_match("/img/"){  echo "检测到图片";  }else{  echo "未发现图片";} 不过说真的,这种判断方法太牵强了。 判断文章中是否有图片的例子,请参考如下文章: php preg_match_all匹配文章中图片php处理文章中图片的方法PHP正则过滤文章中图片的方法php用preg_match_all匹配文章中的图片

php怎么判断gif图片是否为动画?

{$fp=fopen($filename, rb); $filecontent=fread($fp, filesize($filename));fclose($fp);return strpos($filecontent,chr(0x21).chr(0xff).chr(0x0b).NETSCAPE2.0)===FALSE?0:1;} // bbs.it-home.orgecho IsAnimatedGif("zzsky.gif");?>

php如何判断图片颜色类型?实例教程

<?php$i = imagecreatefromjpeg("image.jpg"); for ($x=0;$x<imagesx($i);$x++) { for ($y=0;$y<imagesy($i);$y++) { $rgb = imagecolorat($i,$x,$y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF; $rTotal += $r; $gTotal += $g; $bTotal += $b; $total++; } } // bbs.it-home.org$rAverage = round($rTotal/$total); $gAverage = round($gTotal/$tot...

php判断数组是否全部相同方法详解

//伪造有100000个数组元素的数组,第一个数组元素为1,后面的99999个都为0 for($i=0;$i<100000;$i++){ if($i==1) array_push($array,1); else array_push($array,0); } //第一种用循环方法 $len=count($array); for ($i=0; $i <$len ; $i++) { if($array[$i]!=$array[$i+1]){ break; } } // 耗时:Processed in 0.144372 second(s). 借助php中的array_count_values()去完成if(count(array_count_values($ar...

zf判断请求是否来自XMLHttpRequest对象的方法

/** * Is the request a Javascript XMLHttpRequest? * * Should work with Prototype/Script.aculo.us, possibly others. * * @return boolean */ public function isXmlHttpRequest() { return ( $this->getHeader(X_REQUESTED_WITH) == XMLHttpRequest);}

php文件类型检测:根据二进制文件头判断文件类型的函数

<?php$files = array(./test.jpg, test.png);$fileTypes = array( 7790 => exe, 7784 => midi, 8075 => zip, 8297 => rar, 225216 => jpg, 7173 => gif, 6677 => bmp, 13780 => png,);foreach($files as $file) { $fp = fopen($file, rb); $bin = fread($fp, 2); // 只读头两个字节 fclose($fp); $strInfo = @unpack("C2chars", $bin); $typeCode = intval($strInfo[chars1].$strInfo[chars2]); $fileType ...

php怎么判断手机客户端访问?

<?php// check if wap function check_wap(){ if(stristr($_SERVER[HTTP_VIA],"wap")){// 先检查是否为wap代理,准确度高 return true; }elseif(strpos(strtoupper($_SERVER[HTTP_ACCEPT]),"VND.WAP.WML") > 0){// 检查浏览器是否接受 WML. return true; }elseif(preg_match(/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Go...

php如何判断数据类型?php数据类型判断函数有哪些?

在php中数据类型怎么判断,php判断数据类型的常用函数有哪些,在php中判断字符串类型、数字类型、布尔类型等其它php变量类型的函数,供大家学习参考。 php判断数据类型的函数 一、php如何判断数据类型?可以使用如下函数: isset(): //变量是否已经声明 empty(): //变量是否为空 defined(): //常量是否已经定义 define() array_key_exists(mixed key, array search): //检查给定的键名或索引是否存在于数组中 is_numeric ( mix...

判断客户端浏览器的类型

如上所述,很多时候我们需要知道用户的浏览器类型 /** * 判断浏览器名称和版本 */ function get_user_browser() { if (empty($_SERVER[HTTP_USER_AGENT])) { return ; } $agent = $_SERVER[HTTP_USER_AGENT]; $browser = ; $browser_ver = ; if (...

判断手机访问

/* QQ:297003558 http://blog.ddian.cn http://qita.in /*//手机来访function is_mobile() { $user_agent = $_SERVER[HTTP_USER_AGENT]; $mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu","cdm-","c...