php 截取utf 8字符串
找了很多这样的函数,还是觉的这个最好了
$a = 'aadfdsf夺顶替一枯基22245顶替sdffh压下';
/**
* 截取utf-8字符
* @param string $string
* @param int$length
*
* return string
*/
function cutstr($string, $length) {
preg_match_all("/./u", $string, $info);
$i = 0;
$str = '';
foreach($info[0] as $item){
if(strlen($item) == 3){
$i+=2;
}else{
$i++;
}
$str .= $item;
if($i>=$length)break;
}
return $str;
}
echo cutstr($a, 10); //-> aadfdsf夺顶
相关文档:
方法1:error_reporting (E_ALL ^ E_WARNING);
session_start();
方法2:error_reporting (E_ALL & ~E_NOTICE);
if (!isset($_SESSION)) {
session_start();
};
方法3:改php.ini 中error_reporting ......
搞了很久。。终于发现原来是权限问题。。
2行命令搞定
grant all privileges on rogue.* to admin@localhost identified by 'admin' with grant option
grant all privileges on rogue.* to admin@'%' identified by 'admin' with grant option
经典了。。。
魔力私服网页端搞定咯~~ ......
我们知道用powerdesigner导出的sql文件后缀为'.sql';用phpmyadmin很容易导入MysQL数据库,但是用PHP怎么导入数据库呢?
我用powerdesigner设计一个数据库后导出sql文件(一个投票系统)为'vote.sql';
文件内容为(一些sql语句和注释):
/*======================= ......
PHP中文乱码是PHP开发中的常见问题之一。PHP中文乱码有时发生在网页本身,有些产生在于MySQL交互的过程中,有时与操作系统有关。下
面进行一番总结。
一.首先是PHP网页的编码
1. php文件本身的编码与网页的编码应匹配
a. 如果欲使用gb2312编码,那么php要输出头:header(“Content-Type: text/html; ......
<p>04级新生名单</p>
<table border="1" width="80%" cellpadding="0">
<tr>
<td width="10%" align="center">Id</td>
<td width="20%" align="center">Name</td>
<td width="10%" align="center">Age</td>
<td width="10%" align="cent ......