PHP检查库或函数是否可用的方法
获取所有可用的模块 - get_loaded_extensions
该函数返回所有已经加载的(可用的)模块。
用法:
print_r(get_loaded_extensions());
2. 获取指定模块的可用函数 - get_extension_funcs
该函数返回指定模块所有可用的函数。传入的参数(模块名称)必须是小写
用法:
print_r(get_extension_funcs("gd"));
3. 获取所有已经定义的函数 - get_defined_functions
该函数返回所有已经定义的函数,包括内置函数和用户自定义函数。
用法:
function myrow($id, $data){
return "<tr><th>$id</th><td>$data</td></tr>\n";
}
$arr = get_defined_functions();
print_r($arr);
输出:
Array
(
[internal] => Array
(
[0] => zend_version
[1] => func_num_args
[2] => func_get_arg
[3] => func_get_args
[4] => strlen
[5] => strcmp
[6] => strncmp
...
[750] => bcscale
[751] => bccomp
)
[user] => Array
(
[0] => myrow
)
)
其中 $arr["internal"] 是内置函数, $arr["user"] 是用户自定义函数。
4. 检查指定函数是否存在 - function_exists
该函数返回指定函数是否已经定义。
用法:
if (function_exists('imap_open')) {
echo "IMAP functions are available.<br />\n";
} else {
echo "IMAP functions are not available.<br />\n";
}
<?php
/*正则取图片img标记中的任意属性*/
$word = '<p height="22" align="cenetr">111 22</p> <img src="/upload/images/aaa.jpg" width="100" height="50"/><div style="float:left;">中国人</div>';
//取整个图片代码
preg_match('/<img(.[^<]*)src="?(.[^<"]*)"?(.[^<|/]*)/?>/is',$word,$matches);
echo $matches[0];//结果:<img src="/upload/images/aaa.jpg" width="100">
$word = '<p height="22" align="cenetr">111 22</p> <img height="60" src="/upload/images/aaa.jpg" width="100" style=><div style="float:left;">中国人</div>';
//取width
preg_match('/<img.+(width="?d*"?).+>/i',$word,$matches);
echo $matches[1];
//取height
preg_match('/<img.+(height="?d*"?).+>/i',$word,$matches);
echo $matches[1];
//取src
preg_match('/<img.+src="?(.+.(jpg|gif|bmp|bnp|png))"?.+>/i',$word,$matches);
echo $matches[1];
/*正则替换去掉或改变图片img标记中的任意属性***************************************************************/
$str = '<p height="22" align="cenetr">111 22</p> <img height="60" src="/upload/images/aaa.jpg" width=100 style=><div style="float:left;">中国人</div><p height="22" align="cenetr">31313 224344</p> <img src="/upload/images/bbb.jpg" height="60" width=100 style=><div style="float:left;">1212121</div>';
//改变src属性(此处将原来的src="/upload/images/bbb.jpg"改变为src="/upload/_thumbs/Images/bbb.jpg")
print preg_replace('/(<img.+src="?.+)(images/)(.+.(jpg|gif|bmp|bnp|png)"?.+>)/i',"${1}_thumbs/Images/${3}",$str);
/*改变src属性,
此处将原来的src="/upload/images/bbb.jpg"改变为src="/upload/_thumbs/Images/bbb.jpg",并舍弃宽和高
(比如你想在前台显示缩略图,但数据库教程中存储的是原图的路径。为什么要舍弃宽高??你缩略图啊!还是原图的宽高,会怎样???)
*/
print preg_replace('/(<img).+(src="?.+)images/(.+.(jpg|gif|bmp|bnp|png)"?).+>/i',"${1} ${2}_thumbs/Images/${3}>",$str);
<?php教程
// Ask for Input
fwrite(STDOUT, "Please Select Option(Default is Find) [1]Find [2]Replace Please Input Number: ");
// Get Input
$todo = trim(fgets(STDIN));
if(empty($todo)) $todo =1;
if($todo != 1 && $todo !=2){
echo "Selected Error! ";
exit;
}
if($todo==1){
fwrite(STDOUT,"Please Input Find Directory(Default is Current Directory):");
$dir = trim(fgets(STDIN));
if(empty($dir)){
$dir = getcwd();//当前目录
}else{
if(!is_dir($dir)){
echo "Directory Not Exist! ";
exit;
}
}
fwrite(STDOUT,"Please Input Content of the Find:");
$search = trim(fgets(STDIN));
echo "In Directory'".$dir."'Find'".$search."',Please Wait... ";
exec("find ".$dir." -exec grep --exclude='*.svn/*' -- '".$search."' {} +",$output);
foreach($output as $val){
echo "$val ";
}
}else{// write input back
fwrite(STDOUT, "Please Input Find Directory(Default is Current Directory):");
$dir = trim(fgets(STDIN));
if(empty($dir)){
$dir = getcwd();//当前目录
}else{
if(!is_dir($dir)){
echo "Directory Not Exist! ";
exit;
}
}
fwrite(STDOUT,"Please Input Prefix(Default is php):");
$ext = trim(fgets(STDIN));
if(empty($ext)) $ext = 'php';
fwrite(STDOUT,"Please Input Find Content:");
$search = trim(fgets(STDIN));
fwrite(STDOUT,"Please Input Replace Content:");
$replace = trim(fgets(STDIN));
echo "正在目录'".$dir."'查找后缀为'".$ext."'的文件,将内容'".$search."'替换为'".$replace."',请稍后... ";
exec("find ".$dir." -name '*.".$ext."' -exec sed --in-place 's/".$search."/$replace/g' {} ;");
echo "Replace Completed! ";
}
?>
/**************************************************************
02 *
03 * 使用特定function对数组中所有元素做处理
04 * @param string &$array 要处理的字符串
05 * @param string $function 要执行的函数
06 * @return boolean $apply_to_keys_also 是否也<SPAN class=t_tag onclick=tagshow(event) href="tag.php教程?name=%D3%A6%D3%C3">应用</SPAN>到key上
07 * @access public
08 *
09 *************************************************************/
10 function arrayRecursive(&$array, $function, $apply_to_keys_also = false)
11 {
12 foreach ($array as $key => $value) {
13 if (is_array($value)) {
14 arrayRecursive($array[$key], $function, $apply_to_keys_also);
15 } else {
16 $array[$key] = $function($value);
17 }
18
19 if ($apply_to_keys_also && is_string($key)) {
20 $new_key = $function($key);
21 if ($new_key != $key) {
22 $array[$new_key] = $array[$key];
23 unset($array[$key]);
24 }
25 }
26 }
27 }
28
29 /**************************************************************
30 *
31 * 将数组转换为JSON字符串(兼容中文)
32 * @param array $array 要转换的数组
33 * @return string 转换得到的json字符串
34 * @access public
35 *
36 *************************************************************/
37 function JSON($array) {
38 arrayRecursive($array, 'urlencode', true);
39 $json = json_encode($array);
40 return urldecode($json);
41 }
AdodbZip1.1有更新,更新了下载地址。
SmartyZip,一个Smarty的装载类
<?php教程
// 设定参数
SmartyZip::$zip_url = 'http://www.smarty.net教程/distributions/Smarty-2.6.26.zip'; //[设置项]Smarty的Zip文件下载地址
SmartyZip::$zip_file = sys_get_temp_dir () . preg_replace ( '/^.*/(Smarty-.*.zip)$/i', 'smarty/$1', SmartyZip::$zip_url ); //[设置项]Smarty的Zip文件缓存位置
SmartyZip::$entry_dir = preg_replace ( '/^.*/(Smarty-.*).zip$/i', '$1/libs', SmartyZip::$zip_file );
SmartyZip::$extract_dir = sys_get_temp_dir () . 'smarty/' . SmartyZip::$entry_dir; //[设置项]Smarty程序文件缓存位置
SmartyZip::$template_dir = dirname ( realpath ( __FILE__ ) ); //[设置项]Smarty模板文件 所在位置
SmartyZip::$compile_dir = sys_get_temp_dir () . 'smarty/template_c/' . md5 ( SmartyZip::$template_dir ); //[设置项]Smarty编译文件缓存位置
// 注册协议
if (! in_array ( 'SmartyZip', stream_get_wrappers () )) {
stream_wrapper_register ( 'SmartyZip', 'SmartyZip' );
}
// 定义常量
if (! defined ( 'SMARTY_DIR' )) {
define ( 'SMARTY_DIR', 'SmartyZip://' );
}
// 包含程序
require_once (SMARTY_DIR . 'Smarty.class.php');
// $smarty = SmartyZip::init(new Smarty); // [选择项]引用即定义$smarty
// return SmartyZip::init(new Smarty); // [选择项]引用即返回$smarty,注意只可引用一次。
/**
* SmartyZip类定义
*/
class SmartyZip {
/**
* Smarty变量
*/
public static $zip_url;
public static $zip_file;
public static $entry_dir;
public static $extract_dir;
public static $template_dir;
public static $compile_dir;
/**
* Stream变量
*/
private $handle;
public $context;
/**
* Smarty函数组
*/
/**
* init
* @param Smarty &$smarty
* @return Smarty
*/
public static function init(&$smarty) {
$smarty->template_dir = self::$template_dir;
if (! is_dir ( self::$compile_dir )) {
if (mkdir ( self::$compile_dir, 0777, true ) === false) {
header ( 'Content-type: text/html;charset=utf-8' );
die ( '请创建目录 ' . self::$compile_dir );
}
}
$smarty->compile_dir = self::$compile_dir;
return $smarty;
}
/**
* Stream函数组
*/
/**
* __construct
*/
public function __construct() {
}
/**
* stream_cast
* @param int $cast_as
* @return resource
*/
public function stream_cast($cast_as) {
return false;
}
/**
* stream_close
*/
public function stream_close() {
fclose ( $this->handle );
}
/**
* stream_eof
* @return bool
*/
public function stream_eof() {
return feof ( $this->handle );
}
/**
* stream_flush
* @return bool
*/
public function stream_flush() {
return fflush ( $this->handle );
}
/**
* stream_lock
* @param mode $options
* @return bool
*/
public function stream_lock($options) {
return flock ( $this->handle, $options );
}
/**
* stream_open
* @param string $path
* @param string $mode
* @param int $options
* @param string &$opend_path
* @return bool
*/
public function stream_open($path, $mode, $options, &$opend_path) {
// 验证文件地址
if (! preg_match ( '/^.*?://(.*)$/', $path, $matches )) {
return false;
}
$tmp_file = self::$extract_dir . DIRECTORY_SEPARATOR . $matches [1];
$entry_file = self::$entry_dir . '/' . str_replace ( '\', '/', $matches [1] );
$zip_file = self::$zip_file;
// 验证程序文件
if (! file_exists ( $tmp_file ) || file_exists ( $zip_file ) && filectime ( $tmp_file ) < filectime ( $zip_file )) {
// 下载文件
if (! file_exists ( $zip_file )) {
// 目录处理
if (! is_dir ( dirname ( self::$zip_file ) )) {
if (mkdir ( dirname ( self::$zip_file ), 0777, true ) === false) {
header ( 'Content-type: text/html;charset=utf-8' );
die ( '请创建目录 ' . $zip_dir );
}
}
// 下载文件
if (! file_exists ( self::$zip_file )) {
$break = true;
do {
$url_arr = parse_url ( self::$zip_url );
$fp = fsockopen ( $url_arr ['host'], isset ( $url_arr ['port'] ) ? ( int ) $url_arr ['port'] : 80, $errno, $errstr, 10 );
if ($fp === false) {
break;
}
$out = "GET " . $url_arr ['path'] . " HTTP/1.0rnHost: " . $url_arr ['host'] . " rnConnection: closernrn";
fputs ( $fp, $out );
if (feof ( $fp )) {
break;
}
$buffer = fgets ( $fp, 1024 );
if (! preg_match ( '/^HTTP/1.d 200 /i', $buffer )) {
break;
}
$content_length = false;
$content_start = false;
while ( ! feof ( $fp ) ) {
$buffer = fgets ( $fp, 1024 );
if ($buffer === "rn") {
$content_start = true;
break;
}
if (preg_match ( '/^Content-Length:s*(d+)/i', $buffer, $matches )) {
$content_length = ( int ) $matches [1];
}
}
if ($content_length === false || $content_start === false) {
break;
}
$content = stream_get_contents ( $fp );
if ($content === false) {
break;
}
$result = file_put_contents ( self::$zip_file, $content );
unset ( $content );
if ($result === false) {
break;
}
fclose ( $fp );
} while ( $break = false );
if ($break) {
header ( 'Content-type: text/html;charset=utf-8' );
die ( '请下载文件 <a href="' . self::$zip_url . '">' . self::$zip_url . '</a > 保存为 ' . self::$zip_file );
}
}
}
// 创建目录
$tmp_dir = dirname ( $tmp_file );
if (! is_dir ( $tmp_dir )) {
if (mkdir ( $tmp_dir, 0777, true ) === false) {
header ( 'Content-type: text/html;charset=utf-8' );
die ( '请创建目录 ' . $tmp_dir );
}
}
// 打开压缩文件
$zip = zip_open ( $zip_file );
if (! is_resource ( $zip )) {
return false;
}
// 寻找解压文件
do {
$entry = zip_read ( $zip );
if (! is_resource ( $entry )) {
return false;
}
if (zip_entry_name ( $entry ) == $entry_file) {
break;
}
} while ( true );
// 转存压缩文件
zip_entry_open ( $zip, $entry );
file_put_contents ( $tmp_file, zip_entry_read ( $entry, zip_entry_filesize ( $entry ) ) );
zip_entry_close ( $entry );
zip_close ( $zip );
}
// 打开文件
$this->handle = fopen ( $tmp_file, $mode );
if (! is_resource ( $this->handle )) {
return false;
}
return true;
}
/**
* stream_read
* @param int $count
* @return string
*/
public function stream_read($count) {
return fread ( $this->handle, $count );
}
/**
* stream_seek
* @param int $offset
* @param int $whence=SEEK_SET
* @return bool
*/
public function stream_seek($offset, $whence = SEEK_SET) {
return fseek ( $this->handle, $offset, $whence );
}
/**
* stream_set_option
* @param int $option
* @param int $arg1
* @param int $arg2
* @return bool
*/
public function stream_set_option($option, $arg1, $arg2) {
return false;
}
/**
* stream_stat
* @return array
*/
public function stream_stat() {
return fstat ( $this->handle );
}
/**
* stream_tell
* @return int
*/
public function stream_tell() {
return ftell ( $this->handle );
}
/**
* stream_write
* @param string $data
* @return int
*/
public function stream_write($data) {
return fwrite ( $this->handle, $data );
}
/**
* url_stat
* @param string $path
* @param int $flag
* @return array
*/
public function url_stat($path, $flag) {
if (! preg_match ( '/^.*?://(.*)$/', $path, $matches )) {
return false;
}
$tmp_file = self::$extract_dir . DIRECTORY_SEPARATOR . $matches [1];
if (file_exists ( $tmp_file )) {
if ($flag & STREAM_URL_STAT_LINK) {
return lstat ( $tmp_file );
} else {
return stat ( $tmp_file );
}
}
if ($flag & STREAM_URL_STAT_QUIET) {
$file_stat = lstat ( __FILE__ );
$mode = $file_stat ['mode'];
// smarty plugins adjust
if (strpos ( $matches [1], 'plugins' . DIRECTORY_SEPARATOR . 'compiler.' ) !== false) {
if (strpos ( $matches [1], 'plugins' . DIRECTORY_SEPARATOR . 'compiler.assign.php' ) === false) {
$mode = 0;
}
} elseif (strpos ( $matches [1], 'plugins' . DIRECTORY_SEPARATOR . 'block.' ) !== false) {
if (strpos ( $matches [1], 'plugins' . DIRECTORY_SEPARATOR . 'block.textformat.php' ) === false) {
$mode = 0;
}
}
$arr = array ('dev' => 0, 'ino' => 0, 'mode' => $mode, 'nlink' => 0, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => 0, 'atime' => 0, 'mtime' => 0, 'ctime' => 0, 'blksize' => 0, 'blocks' => 0 );
return array_merge ( array_values ( $arr ), $arr );
}
return false;
}
}
?>
使用Smarty很简单:
1. 包含SmartyZip文件。
2. 使用SmartyZip::init(new Smarty)自动为smarty对象设置默认路径。
样例代码:view sourceprint?1 <?php
2 include_once 'SmartyZip.php';
3 $smarty = SmartyZip::init(new Smarty);
4 $smarty->assign ( 'name', 'SmartyZip' );
5 $smarty->display ( 'test.<SPAN class=t_tag onclick=tagshow(event) href="tag.php?name=html">html</SPAN>' );
6 ?>
相关文章
- eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
- 在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
Python astype(np.float)函数使用方法解析
这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08php 中file_get_contents超时问题的解决方法
file_get_contents超时我知道最多的原因就是你机器访问远程机器过慢,导致php脚本超时了,但也有其它很多原因,下面我来总结file_get_contents超时问题的解决方法总结。...2016-11-25- php如何实现抓取网页图片,相较于手动的粘贴复制,使用小程序要方便快捷多了,喜欢编程的人总会喜欢制作一些简单有用的小软件,最近就参考了网上一个php抓取图片代码,封装了一个php远程抓取图片的类,测试了一下,效果还不错分享...2015-10-30
- 这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
- 相信很多站长都遇到过这样一个问题,访问页面时出现408错误,下面一聚教程网将为大家介绍408错误出现的原因以及408错误的解决办法。 HTTP 408错误出现原因: HTT...2017-01-22
- 本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
- 下面我们来看一篇关于Android子控件超出父控件的范围显示出来方法,希望这篇文章能够帮助到各位朋友,有碰到此问题的朋友可以进来看看哦。 <RelativeLayout xmlns:an...2016-10-02
- 下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
- ps软件是现在非常受大家喜欢的一款软件,有着非常不错的使用功能。这次文章就给大家介绍下ps把文字背景变透明的操作方法,喜欢的一起来看看。 1、使用Photoshop软件...2017-07-06
intellij idea快速查看当前类中的所有方法(推荐)
这篇文章主要介绍了intellij idea快速查看当前类中的所有方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-09-02- 1.在没有设置默认值的情况下: 复制代码 代码如下:SELECT userinfo.id, user_name, role, adm_regionid, region_name , create_timeFROM userinfoLEFT JOIN region ON userinfo.adm_regionid = region.id 结果:...2014-05-31
js导出table数据到excel即导出为EXCEL文档的方法
复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta ht...2013-10-13- 批量更新mysql更新语句很简单,更新一条数据的某个字段,一般这样写:复制代码 代码如下:UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_value';如果更新同一字段为同一个值,mysql也很简单,修改下where即...2013-10-04
- ps软件是一款非常不错的图片处理软件,有着非常不错的使用效果。这次文章要给大家介绍的是ps怎么制作倒影,一起来看看设计倒影的方法。 用ps怎么做倒影最终效果̳...2017-07-06
- CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
- 本文涉及的主题虽然很基础,在许多人看来属于小伎俩,但在JavaScript基础知识中属于一个综合性的话题。这里会涉及到对象属性的封装、原型、构造函数、闭包以及立即执行表达式等知识。公有方法 公有方法就是能被外部访问...2015-11-08
安卓手机wifi打不开修复教程,安卓手机wifi打不开解决方法
手机wifi打不开?让小编来告诉你如何解决。还不知道的朋友快来看看。 手机wifi是现在生活中最常用的手机功能,但是遇到手机wifi打不开的情况该怎么办呢?如果手机wifi...2016-12-21- 最近想自学PHP ,做了个验证码,但不知道怎么搞的,总出现一个如下图的小红叉,但验证码就是显示不出来,原因如下 未修改之前,出现如下错误; (1)修改步骤如下,原因如下,原因是apache权限没开, (2)点击打开php.int., 搜索extension=ph...2013-10-04