【获取内存使用信息的PHP代码】教程文章相关的互联网学习教程文章

自动注册登录验证机制的php代码

$urls = parse_url($db_bbsurl); $domain = $urls['host']; include_once (R_P .'require/admvclient.php'); $adm_oem= new Cnzz_Adm_Oem(); //判断config文件是否存在用户密码 pwCache::getData(D_P . "data/bbscache/adm_config.php");//用户名密码 配置文件 if (isset($adm_user) && isset($adm_pwd)) { $request = array("adm_user"=>$adm_user,"adm_pwd"=>$adm_pwd,'cms'=>'pw'); $token = $adm_oem->get_appkey_once($reques...

将网页导出为Word文档的php代码介绍【图】

/** * 根据html代码获取word文档内容 * 创建一个本质为mht的文档,该函数会分析文件内容并从远程下载页面中的图片资源 * 该函数依赖于类MhtFileMaker * 该函数会分析img标签,提取src的属性值。但是,src的属性值必须被引号包围,否则不能提取 * * @param string $content HTML内容 * @param string $absolutePath 网页的绝对路径。如果HTML内容里的图片路径为相对路径,那么就需要填写这个参数,来让该函数自动填补成绝对路径。这...

在文件指定行中写入内容的php代码

$file="aa.php" ; $code=""; $f=fopen($file,"r+"); $content=fread($f,filesize($file)); fclose($f); if(!strstr($content,$code)){ $arrInsert = insertContent($file, $code, 3); unlink($file); foreach($arrInsert as $value) { file_put_contents($file, $value, FILE_APPEND); } } function insertContent($source, $s, $iLine) { $file_handle = fopen($source, "r"); $i = 0; $arr = array(); while (!feof($file_handle...

判断对文件空目录是否有读写权限的php代码

判断对文件空目录是否有读写权限的php代码 is_writable用来处理,记住 PHP 也许只能以运行 webserver 的用户名(通常为 \nobody\)来访问文件。不计入安全模式的限制。 Example #1 is_writable() 例子 <?php $filename = test.txt; if (is_writable($filename)) { echo The file is writable; } else { echo The file is not writable; } ?>上面的函数有一个问题就是filename 必需。规定要检查的文件 ,必须是文件啊,目录不...

压缩多个CSS与JS文件的php代码

header('Content-type: text/css'); ob_start("compress"); function compress($buffer) { /* remove comments */ $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); /* remove tabs, spaces, newlines, etc. */ $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer); return $buffer; } ...

自动生成文章摘要的php代码

// PHP 4.3 or above needed define("BRIEF_LENGTH", 800); //Word amount of the Briefing of an Article function Generate_Brief($text){ global $Briefing_Length; if(strlen($text) $Foremost = substr($text, 0, BRIEF_LENGTH); $re = "/]*(>?)/i"; $Single = "/BASE|META|LINK|HR|BR|PARAM|IMG|AREA|INPUT/i"; $Stack = array(); $posStack = array(); preg_match_all($re,$Foremost,$matches, PREG_SET_ORDER | PREG_OFFSE...

将IP地址和数字相互转化的php代码

$ip = "182.18.8.196";echo ;echo ip2long($ip);echo " @ ";echo $ipfu = ip2int($ip);echo @ ;$ip_n = bindec(decbin(ip2long($ip)));echo $ip_n;echo @ ;echo long2ip($ip_n);echo @ ;echo long2ip($ipfu);//数字转化成IP//可以直接采用本函数来得出ip地址转化成的数字。function myip2long($ip){return bindec(decbin(ip2long($ip)));}//此函数和ip2long 等同function ip2int($ip){list($ip1,$ip2,$ip3,$ip4)=explode(".",$i...

验证用户输入的邮箱有效性与正确性的php代码

<?phpfunction validate_email($email){$exp="^[a-z0-9]+([._-][a-z0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";if(eregi($exp,$email)){ //先用正则表达式验证email格式的有效性if(checkdnsrr(array_pop(explode("@",$email)),"MX")){//再用checkdnsrr验证email的域名部分的有效性 return true;}else{ return false;}}else{ return false;}}//注意:checkdnsrr函数在win主机上是无效的!下面是国外某程序员提出的一种解决办法,...

从数组中随机抽取一些元素的php代码

<?php/*** 随机抽取数组元素* author: notuser* 2012-12-29*/class getValues {public function inputValue($inputArray) {$this->inputArray = $inputArray;}public function getValue($number) {$this->number = $number;for($i = 0; $i < $this->number; $i ++) {$index = rand ( 0, count ( $this->inputArray ) - 1 - $i );$getArray [$i] = $this->inputArray [$index];unset ( $this->inputArray [$index] );for($k = $inde...

将图片保存为不同规格的图片的php代码

/**图片处理类 */class imagecls{ /** * 文件信息 */ var $file = array(); /** * 保存目录 */ var $dir = ''; /** * 错误代码 */ var $error_code = 0; /** * 文件上传最大KB */ var $max_size = -1; function es_imagecls() { } private function checkSize($size) { return !($size > $this->max_size) || (-1 == $this->max_size); } /** * 处理上传文件 * @param array $file 上传的文件 * @...

提取一个图像文件并在浏览器上显示的php代码

$size = getimagesize($filename); //获取mime信息$fp=fopen($filename, "rb"); //二进制方式打开文件if ($size && $fp) {header("Content-type: {$size['mime']}");fpassthru($fp); // 输出至浏览器exit;} else {// error}?> 代码量是原来的1/10都不到,速度快了N倍。

查看php代码运行时间的类

/*** 功能:查看php代码的运行时间* 日期:2012-12-29* 文件:show_php_runtime.php**/class RunTime//页面执行时间类{private $starttime;//页面开始执行时间private $stoptime;//页面结束执行时间private $spendtime;//页面执行花费时间function getmicrotime()//获取返回当前微秒数的浮点数{list($usec,$sec)=explode(" ",microtime());return ((float)$usec + (float)$sec);}function start()//页面开始执行函数,返回开始页面...

用来自动压缩js文件的php代码

/* 9 April 2008. version 1.1 * * This is the php version of the Dean Edwards JavaScript's Packer, * Based on : * * ParseMaster, version 1.0.2 (2005-08-19) Copyright 2005, Dean Edwards * a multi-pattern parser. * KNOWN BUG: erroneous behavior when using escapeChar with a replacement * value that is a function * * packer, version 2.0.2 (2005-08-19...

文本转HTML的php代码

<php//文本转HTMLfunction Text2Html($txt){$txt = str_replace(” ”,” ”,$txt);$txt = str_replace(“<”,”<”,$txt);$txt = str_replace(“>”,”>”,$txt);$txt = preg_replace(“/[\r\n]{1,}/isU”,”\r\n”,$txt);return $txt;}?>

GBK页面输出JSON的php代码

function tb_json_encode($value, $options = 0){ return json_encode(tb_json_convert_encoding($value, “GBK”, “UTF-8″));}function tb_json_decode($str, $assoc = false, $depth = 512){ return tb_json_convert_encoding(json_decode($str, $assoc), “UTF-8″, “GBK”);}function tb_json_convert_encoding($m, $from, $to){ switch(gettype($m)) { case ‘integer’: case ‘boolean’: case ‘float’: ...