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.下载安装mcrypt
先去http://www.sourceforge.net下载Libmcrypt,mhash,mcrypt安装包
2 .先安装Libmcrypt
#tar -zxvf libmcrypt-2.5.8.tar.gz
#cd libmcrypt-2.5.8
#./configure
#make
#make install
说明:libmcript默认安装在/usr/local
3.安装mhash
#tar -zxvf mhash-0.9.9.9.tar.gz
#cd mhash-0.9.9.9
#./ ......
最近在学PHP ,觉得比较简单,可能是因为有一点编程经验的缘故吧,今天教大家用PHP制作通讯录,功能比较简单,第一次做网页教程,而且不是很有PHP经验,所以不足的地方大家留言告诉我,废话不多说,现在开始
环境:Windows XP SP3 + PHP5 + apache2 + mysql5
首先创建一个数据库,名为 MyDB (我这里使用的是MySQL),SQL ......
代码interface StringSearchable
{
public function search($substring, $buffer);
}
class BoyerMooreStringSearch implements StringSearchable
{
public $substring = null;
public ......
<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 ......
$pagesize=10; //设置每一页显示的记录数
$c("localhost","root",""); //连接数据库
$rs=mysql_query("select count(*) from tb_product",$conn); //取得记录总数$rs
$myrow = mysql_fetch_array($rs);
$numrows=$myrow[0];
Ɍ ......