function cut_str($string, $sublen, $start = 0, $code = 'UTF-8', $ext = '') { if ($code == 'UTF-8') { $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/"; preg_match_all ( $pa, $string, $t_string ); if (count ( $t_string [0] ) - $start > $sublen) return join ( '', array_slice ( $t_string [0], $start, $sublen ) ) . $ext; return join ( '', array_slice ( $t_string [0], $start, $sublen ) ); } else { $start = $start * 2; $sublen = $sublen * 2; $strlen = strlen ( $string ); $tmpstr = ''; for($i = 0; $i < $strlen; $i ++) { if ($i >= $start && $i < ($start + $sublen)) { if (ord ( substr ( $string, $i, 1 ) ) > 129) { $tmpstr .= substr ( $string, $i, 2 ); } else { $tmpstr .= substr ( $string, $i, 1 ); } } if (ord ( substr ( $string, $i, 1 ) ) > 129) $i ++; } if (strlen ( $tmpstr ) < $strlen) $tmpstr .= $ext; return $tmpstr; } }
如果想删除linux系统中一个目录下某个文件,包括子目录下的这个文件,如删除一个目录下所有的.svn文件夹,可以用下面这个命令。
find 要查找的目录名 -name .svn |xargs rm -rf
今天我的一个域名到期了,可是图片的url地址在mysql中存储的还是之前用的那个域名,造成等图片正常显示,想到用mysql的批量替换,将原来的域名替换成现在的域名。用到了下面的mysql命令
UPDATE 表名 SET 字段 = REPLACE(字段,'待替换内容','替换值');
上张图片
UPDATE notes SET note_content=REPLACE(note_content, '51makeit', 'keepdoit' );
再看下面的一个例子:
想讲title中的“第*讲:”去掉,可以用到这个命令
SELECT id,kid,title FROM `ke_classroom` WHERE kid=148; #update ke_classroom set title = replace(title, title,substring(title, locate(':', title)+1)) WHERE kid=148;
给定一个整数值的秒值,将其换算成时分秒形式的值,如:3599秒换算成:00:59:59
<?php $second = 3599; $h = floor($second / 3600) ; $h = $h > 9 ? $h : '0' . $h; $m = floor(($second % 3600) / 60) ; $m = $m > 9 ? $m : '0' . $m; $s = $second - $h * 3600 - $m * 60; $s = $s > 9 ? $s : '0' . $s; $time = $h . ':' . $m . ':' . $s; echo $time;
$array = array(1=>'one', 2=>'two', 3=>'three', 4=>4, 5=>5); error_log('$array = ' . print_r($array, true) . "\n", 3, "/tmp/error.log"); //或 error_log('$array = ' . var_export($array, true) . "\n", 3, "/tmp/error.log");
tail -f /tmp/error.log
输出:
$array = Array
(
[1] => one
[2] => two
[3] => three
[4] => 4
[5] => 5
)
$array = array (
1 => 'one',
2 => 'two',
3 => 'three',
4 => 4,
5 => 5,
)
注: