当前位置: 编程技术>php
本页文章导读:
▪php smarty函数扩展
中文截取 modifier.cn_truncate.php 代码如下: function smarty_modifier_cn_truncate($string, $strlen = 20, $etc = '...', $keep_first_style = false) { $strlen = $strlen*2; $string = trim($string); if ( strlen($string) <= $strlen ) { return $s.........
▪php Smarty date_format [格式化时间日期]
Example 5-8. date_format[日期格式] index.php: 代码如下: $smarty = new Smarty; $smarty->assign('yesterday', strtotime('-1 day')); $smarty->display('index.tpl'); index.tpl: {$smarty.now|date_format} {$smarty.now|date_format:"%A, %B %e, .........
▪libmysql.dll与php.ini是否真的要拷贝到c:\windows目录下呢
是否一定要这样做呢?很多网上的帖子都是人云亦云,别人说要,他也说要。 其实用的,每次重装系统,都这样拷一遍,折腾一遍,太辛苦了。 用过APMServ这个傻瓜式安装包的朋友可能会发.........
[1]php smarty函数扩展
来源: 互联网 发布时间: 2013-11-30
中文截取 modifier.cn_truncate.php
function smarty_modifier_cn_truncate($string, $strlen = 20, $etc = '...',
$keep_first_style = false)
{
$strlen = $strlen*2;
$string = trim($string);
if ( strlen($string) <= $strlen ) {
return $string;
}
$str = strip_tags($string);
$j = 0;
for($i=0;$i<$strlen;$i++) {
if(ord(substr($str,$i,1))>0xa0) $j++;
}
if($j%2!=0) $strlen++;
$rstr=substr($str,0,$strlen);
if (strlen($str)>$strlen ) {$rstr .= $etc;}
if ( $keep_first_style == true && ereg('^<(.*)>$',$string) ) {
if ( strlen($str) <= $strlen ) {
return $string;
}
$start_pos = strpos($string,substr($str,0,4));
$end_pos = strpos($string,substr($str,-4));
$end_pos = $end_pos+4;
$rstr = substr($string,0,$start_pos) . $rstr . substr($string,$end_pos,strlen($string));
}
return $rstr;
}
modifier.ubb.php
<?php
function smarty_modifier_ubb($str) {
$ubbs['quote'][0] = '/\[quote\](.*?)\[\/quote\]/s';
$ubbs['quote'][1] = '<blockquote>引用:<hr size=1>\1<hr size=1></blockquote>';
$ubbs['b'][0] = '/\[b\](.*?)\[\/b\]/s';
$ubbs['b'][1] = '<b>\1</b>';
$ubbs['i'][0] = '/\[i\](.*?)\[\/i\]/s';
$ubbs['i'][1] = '<i>\1</i>';
$ubbs['u'][0] = '/\[u\](.*?)\[\/u\]/s';
$ubbs['u'][1] = '<u>\1</u>';
$ubbs['li'][0] = '/\[li\](.*?)\[\/li\]/s';
$ubbs['li'][1] = '<li>\1</li>';
$ubbs['img'][0] = '/\[img\](.*?)\[\/img\]/s';
$ubbs['img'][1] = '<img border="0" src="/1/index.html">';
$ubbs['img2'][0] = '/\[img=([^,]+),([^\]]+)\](.*?)\[\/img\]/s';
$ubbs['img2'][1] = '<img border="0" width="\1" height="\2" src="/3/index.html">';
$ubbs['url'][0] = '/\[url\](.*?)\[\/url\]/s';
$ubbs['url'][1] = '<a href="/1/index.html" target="_blank">\1</a>';
$ubbs['url2'][0] = '/\[url=([^\]]+)\](.*?)\[\/url\]/s';
$ubbs['url2'][1] = '<a href="/1/index.html" target="_blank">\2</a>';
$ubbs['email'][0] = '/\[email=([^\]]+)\](.*?)\[\/email\]/s';
$ubbs['email'][1] = '<a href="mailto:\2">\2</a>';
$ubbs['qq'][0] = '/\[qq\]([0-9]{5,10})\[\/qq\]/s';
$ubbs['qq'][1] = '<a target="new" href="tencent://message/?uin=\1&Site=www.52515.net&Menu=yes"><img border="0" src="http://wpa.qq.com/pa?p=1:\1:\1" alt="点击这里给我发消息"></a>';
$ubbs['color'][0] = '/\[color=([^\]]+)\](.*?)\[\/color\]/s';
$ubbs['color'][1] = '<font color="\1">\2';
$ubbs['font'][0] = '/\[font=([^\]]+)\](.*?)\[\/font\]/s';
$ubbs['font'][1] = '<font face="\1">\2';
$ubbs['size'][0] = '/\[size=([0-9]+)\](.*?)\[\/size\]/s';
$ubbs['size'][1] = '<font size="\1" >\2';
$ubbs['sizept'][0] = '/\[size=([0-9,pt]+)\](.*?)\[\/size\]/s';
$ubbs['sizept'][1] = '<font >\2';
$ubbs['align'][0] = '/\[align=([^\]]+)\](.*?)\[\/align\]/s';
$ubbs['align'][1] = '<div align="\1">\2';
$ubbs['media'][0] = '/\[media\](.*?)\[\/media\]/s';
$ubbs['media'][1] = '<embed src="/1/index.html"></embed>';
$ubbs['list'][0] = '/\[list\](.*?)\[\/list\]/s';
$ubbs['list'][1] = '<ul>\1</ul>';
$ubbs['list2'][0] = '/\[list=([0-9]+)\](.*?)\[\/list\]/s';
$ubbs['list2'][1] = '<ol>\2</ol>';
$ubbs['indent'][0] = '/\[indent\](.*?)\[\/indent\]/s';
$ubbs['indent'][1] = '<div >\1';
$ubbs['table'][0] = '/\[table([=,0-9,%]*)\](.*?)\[\/table\]/s';
$ubbs['table'][1] = '<table >\2';
$ubbs['tr'][0] = '/\[tr\](.*?)\[\/tr\]/s';
$ubbs['tr'][1] = '<tr>\1';
$ubbs['td'][0] = '/\[td\](.*?)\[\/td\]/s';
$ubbs['td'][1] = '<td > \1';
$ubbs['td2'][0] = '/\[td([^(\]|\[)]+)\](.*?)\[\/td\]/s';
$ubbs['td2'][1] = '<td > \2';
$str = str_replace('[*]','<li>',$str);
foreach ($ubbs as $ubb){
$str = ubb_replace($ubb[0],$ubb[1],$str);
}
return $str;
}
function ubb_replace($pattern,$replacement,$str){
do {
$str_ret = $str;
$str = preg_replace($pattern,$replacement,$str);
}while($$str);
return $str_ret;
}
?>
编码 modifier.unescape.php
function smarty_modifier_unescape($str)
{
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|[^%]+/",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u" && strlen($v) == 6)
$ar[$k] = iconv("UCS-2","GB2312",@pack("H4",substr($v,-4)));
}
return join("",$ar);
}
代码如下:
function smarty_modifier_cn_truncate($string, $strlen = 20, $etc = '...',
$keep_first_style = false)
{
$strlen = $strlen*2;
$string = trim($string);
if ( strlen($string) <= $strlen ) {
return $string;
}
$str = strip_tags($string);
$j = 0;
for($i=0;$i<$strlen;$i++) {
if(ord(substr($str,$i,1))>0xa0) $j++;
}
if($j%2!=0) $strlen++;
$rstr=substr($str,0,$strlen);
if (strlen($str)>$strlen ) {$rstr .= $etc;}
if ( $keep_first_style == true && ereg('^<(.*)>$',$string) ) {
if ( strlen($str) <= $strlen ) {
return $string;
}
$start_pos = strpos($string,substr($str,0,4));
$end_pos = strpos($string,substr($str,-4));
$end_pos = $end_pos+4;
$rstr = substr($string,0,$start_pos) . $rstr . substr($string,$end_pos,strlen($string));
}
return $rstr;
}
modifier.ubb.php
代码如下:
<?php
function smarty_modifier_ubb($str) {
$ubbs['quote'][0] = '/\[quote\](.*?)\[\/quote\]/s';
$ubbs['quote'][1] = '<blockquote>引用:<hr size=1>\1<hr size=1></blockquote>';
$ubbs['b'][0] = '/\[b\](.*?)\[\/b\]/s';
$ubbs['b'][1] = '<b>\1</b>';
$ubbs['i'][0] = '/\[i\](.*?)\[\/i\]/s';
$ubbs['i'][1] = '<i>\1</i>';
$ubbs['u'][0] = '/\[u\](.*?)\[\/u\]/s';
$ubbs['u'][1] = '<u>\1</u>';
$ubbs['li'][0] = '/\[li\](.*?)\[\/li\]/s';
$ubbs['li'][1] = '<li>\1</li>';
$ubbs['img'][0] = '/\[img\](.*?)\[\/img\]/s';
$ubbs['img'][1] = '<img border="0" src="/1/index.html">';
$ubbs['img2'][0] = '/\[img=([^,]+),([^\]]+)\](.*?)\[\/img\]/s';
$ubbs['img2'][1] = '<img border="0" width="\1" height="\2" src="/3/index.html">';
$ubbs['url'][0] = '/\[url\](.*?)\[\/url\]/s';
$ubbs['url'][1] = '<a href="/1/index.html" target="_blank">\1</a>';
$ubbs['url2'][0] = '/\[url=([^\]]+)\](.*?)\[\/url\]/s';
$ubbs['url2'][1] = '<a href="/1/index.html" target="_blank">\2</a>';
$ubbs['email'][0] = '/\[email=([^\]]+)\](.*?)\[\/email\]/s';
$ubbs['email'][1] = '<a href="mailto:\2">\2</a>';
$ubbs['qq'][0] = '/\[qq\]([0-9]{5,10})\[\/qq\]/s';
$ubbs['qq'][1] = '<a target="new" href="tencent://message/?uin=\1&Site=www.52515.net&Menu=yes"><img border="0" src="http://wpa.qq.com/pa?p=1:\1:\1" alt="点击这里给我发消息"></a>';
$ubbs['color'][0] = '/\[color=([^\]]+)\](.*?)\[\/color\]/s';
$ubbs['color'][1] = '<font color="\1">\2';
$ubbs['font'][0] = '/\[font=([^\]]+)\](.*?)\[\/font\]/s';
$ubbs['font'][1] = '<font face="\1">\2';
$ubbs['size'][0] = '/\[size=([0-9]+)\](.*?)\[\/size\]/s';
$ubbs['size'][1] = '<font size="\1" >\2';
$ubbs['sizept'][0] = '/\[size=([0-9,pt]+)\](.*?)\[\/size\]/s';
$ubbs['sizept'][1] = '<font >\2';
$ubbs['align'][0] = '/\[align=([^\]]+)\](.*?)\[\/align\]/s';
$ubbs['align'][1] = '<div align="\1">\2';
$ubbs['media'][0] = '/\[media\](.*?)\[\/media\]/s';
$ubbs['media'][1] = '<embed src="/1/index.html"></embed>';
$ubbs['list'][0] = '/\[list\](.*?)\[\/list\]/s';
$ubbs['list'][1] = '<ul>\1</ul>';
$ubbs['list2'][0] = '/\[list=([0-9]+)\](.*?)\[\/list\]/s';
$ubbs['list2'][1] = '<ol>\2</ol>';
$ubbs['indent'][0] = '/\[indent\](.*?)\[\/indent\]/s';
$ubbs['indent'][1] = '<div >\1';
$ubbs['table'][0] = '/\[table([=,0-9,%]*)\](.*?)\[\/table\]/s';
$ubbs['table'][1] = '<table >\2';
$ubbs['tr'][0] = '/\[tr\](.*?)\[\/tr\]/s';
$ubbs['tr'][1] = '<tr>\1';
$ubbs['td'][0] = '/\[td\](.*?)\[\/td\]/s';
$ubbs['td'][1] = '<td > \1';
$ubbs['td2'][0] = '/\[td([^(\]|\[)]+)\](.*?)\[\/td\]/s';
$ubbs['td2'][1] = '<td > \2';
$str = str_replace('[*]','<li>',$str);
foreach ($ubbs as $ubb){
$str = ubb_replace($ubb[0],$ubb[1],$str);
}
return $str;
}
function ubb_replace($pattern,$replacement,$str){
do {
$str_ret = $str;
$str = preg_replace($pattern,$replacement,$str);
}while($$str);
return $str_ret;
}
?>
编码 modifier.unescape.php
代码如下:
function smarty_modifier_unescape($str)
{
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|[^%]+/",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u" && strlen($v) == 6)
$ar[$k] = iconv("UCS-2","GB2312",@pack("H4",substr($v,-4)));
}
return join("",$ar);
}
[2]php Smarty date_format [格式化时间日期]
来源: 互联网 发布时间: 2013-11-30
Example 5-8. date_format[日期格式]
index.php:
$smarty = new Smarty;
$smarty->assign('yesterday', strtotime('-1 day'));
$smarty->display('index.tpl');
index.tpl:
{$smarty.now|date_format}
{$smarty.now|date_format:"%A, %B %e, %Y"}
{$smarty.now|date_format:"%H:%M:%S"}
{$yesterday|date_format}
{$yesterday|date_format:"%A, %B %e, %Y"}
{$yesterday|date_format:"%H:%M:%S"}
OUTPUT:
Feb 6, 2001
Tuesday, February 6, 2001
:33:00
Feb 5, 2001
Monday, February 5, 2001
:33:00
Example 5-9. date_format conversion specifiers[日期转换说明]
%a - abbreviated weekday name according to the current locale
(根据当地格式输出“星期”缩写格式)
%A - full weekday name according to the current locale
(根据当地格式输出“星期”全称格式)
%b - abbreviated month name according to the current locale
(根据当地格式输出“月”缩写格式)
%B - full month name according to the current locale
(根据当地格式输出“月”全称格式)
%c - preferred date and time representation for the current locale
%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
%d - day of the month as a decimal number (range 00 to 31)
%D - same as %m/%d/%y
%e - day of the month as a decimal number, a single digit is preceded by a
space (range 1 to 31)
%g - Week-based year within century [00,99]
%G - Week-based year, including the century [0000,9999]
%h - same as %b
%H - hour as a decimal number using a 24-hour clock (range 00 to 23)
%I - hour as a decimal number using a 12-hour clock (range 01 to 12)
%j - day of the year as a decimal number (range 001 to 366)
%k - Hour (24-hour clock) single digits are preceded by a blank. (range 0 to 23)
%l - hour as a decimal number using a 12-hour clock, single digits preceeded by
a space (range 1 to 12)
%m - month as a decimal number (range 01 to 12)
%M - minute as a decimal number
%n - newline character
%p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale
%r - time in a.m. and p.m. notation
%R - time in 24 hour notation
%S - second as a decimal number
%t - tab character
%T - current time, equal to %H:%M:%S
%u - weekday as a decimal number [1,7], with 1 representing Monday
%U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
%V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1
is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.
%w - day of the week as a decimal, Sunday being 0
%W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
%x - preferred date representation for the current locale without the time
%X - preferred time representation for the current locale without the date
%y - year as a decimal number without a century (range 00 to 99)
%Y - year as a decimal number including the century
%Z - time zone or name or abbreviation
%% - a literal `%' character
PROGRAMMERS NOTE: date_format is essentially a wrapper to PHP's strftime()
function. You may have more or less conversion specifiers available depending
on your system's strftime() function where PHP was compiled. Check your
system's manpage for a full list of valid specifiers.
程序员提示:date_format本质上是php的strftime()函数的一个包装。
当php被编译的时候你可以或多或少的依靠系统的strftime()转换有效的区分符。
可以查看系统手册的有效区分符的全表.
index.php:
代码如下:
$smarty = new Smarty;
$smarty->assign('yesterday', strtotime('-1 day'));
$smarty->display('index.tpl');
index.tpl:
{$smarty.now|date_format}
{$smarty.now|date_format:"%A, %B %e, %Y"}
{$smarty.now|date_format:"%H:%M:%S"}
{$yesterday|date_format}
{$yesterday|date_format:"%A, %B %e, %Y"}
{$yesterday|date_format:"%H:%M:%S"}
OUTPUT:
代码如下:
Feb 6, 2001
Tuesday, February 6, 2001
:33:00
Feb 5, 2001
Monday, February 5, 2001
:33:00
Example 5-9. date_format conversion specifiers[日期转换说明]
代码如下:
%a - abbreviated weekday name according to the current locale
(根据当地格式输出“星期”缩写格式)
%A - full weekday name according to the current locale
(根据当地格式输出“星期”全称格式)
%b - abbreviated month name according to the current locale
(根据当地格式输出“月”缩写格式)
%B - full month name according to the current locale
(根据当地格式输出“月”全称格式)
%c - preferred date and time representation for the current locale
%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
%d - day of the month as a decimal number (range 00 to 31)
%D - same as %m/%d/%y
%e - day of the month as a decimal number, a single digit is preceded by a
space (range 1 to 31)
%g - Week-based year within century [00,99]
%G - Week-based year, including the century [0000,9999]
%h - same as %b
%H - hour as a decimal number using a 24-hour clock (range 00 to 23)
%I - hour as a decimal number using a 12-hour clock (range 01 to 12)
%j - day of the year as a decimal number (range 001 to 366)
%k - Hour (24-hour clock) single digits are preceded by a blank. (range 0 to 23)
%l - hour as a decimal number using a 12-hour clock, single digits preceeded by
a space (range 1 to 12)
%m - month as a decimal number (range 01 to 12)
%M - minute as a decimal number
%n - newline character
%p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale
%r - time in a.m. and p.m. notation
%R - time in 24 hour notation
%S - second as a decimal number
%t - tab character
%T - current time, equal to %H:%M:%S
%u - weekday as a decimal number [1,7], with 1 representing Monday
%U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week
%V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1
is the first week that has at least 4 days in the current year, and with Monday as the first day of the week.
%w - day of the week as a decimal, Sunday being 0
%W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week
%x - preferred date representation for the current locale without the time
%X - preferred time representation for the current locale without the date
%y - year as a decimal number without a century (range 00 to 99)
%Y - year as a decimal number including the century
%Z - time zone or name or abbreviation
%% - a literal `%' character
PROGRAMMERS NOTE: date_format is essentially a wrapper to PHP's strftime()
function. You may have more or less conversion specifiers available depending
on your system's strftime() function where PHP was compiled. Check your
system's manpage for a full list of valid specifiers.
程序员提示:date_format本质上是php的strftime()函数的一个包装。
当php被编译的时候你可以或多或少的依靠系统的strftime()转换有效的区分符。
可以查看系统手册的有效区分符的全表.
[3]libmysql.dll与php.ini是否真的要拷贝到c:\windows目录下呢
来源: 互联网 发布时间: 2013-11-30
是否一定要这样做呢?很多网上的帖子都是人云亦云,别人说要,他也说要。 其实用的,每次重装系统,都这样拷一遍,折腾一遍,太辛苦了。 用过APMServ这个傻瓜式安装包的朋友可能会发觉,这个东西,在第一次安装后,以后重装系统也不会重新安装的,只要运行一下主程序,就可以运行WAMP的了,不用折腾一遍的。
可能有人会认为它把libmysql.dll拷贝到c:\windows目录下了,其实不是的,不信去找一找。 既然APMServ可以做到,那么我们也可以做得,比对了APMServ和我们安装的WAMP,找到奥妙就在apache的httpd.conf配置文件。 在httpd.conf加载PHP时,大家都知道是添加这句:
LoadModule php5_module E:\server\php528\php5apache2_2.dll 可能有些朋友也知道,添加这句后,就不用把php.ini拷贝到系统目录:
PHPIniDir E:\server\php528\php.ini
现在我说说不用把libmysql.dll拷到系统目录的办法,就是在加载php5_module前,添加这句:
LoadFile "E:\server\php528\libmysql.dll"
可能有人会认为它把libmysql.dll拷贝到c:\windows目录下了,其实不是的,不信去找一找。 既然APMServ可以做到,那么我们也可以做得,比对了APMServ和我们安装的WAMP,找到奥妙就在apache的httpd.conf配置文件。 在httpd.conf加载PHP时,大家都知道是添加这句:
LoadModule php5_module E:\server\php528\php5apache2_2.dll 可能有些朋友也知道,添加这句后,就不用把php.ini拷贝到系统目录:
PHPIniDir E:\server\php528\php.ini
现在我说说不用把libmysql.dll拷到系统目录的办法,就是在加载php5_module前,添加这句:
LoadFile "E:\server\php528\libmysql.dll"
最新技术文章: