首页 > PHP教程

php中英数字混排的字符串分割代码

function smssubstr($string, $length) {
if(strlen($string) <= $length) {
return $string;
}
$strcut = '';
for($i = 0; $i < $length; $i++) {
$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
}
return $strcut;
}
for($i=1; $i<=$smsnum; $i++){
${'smscontent'.$i} = smssubstr($message,$smsper);
$message = str_replace(${'smscontent'.$i},"",$message);
}

阅读全文

IIS+PHP undefined function mysql_connect()

 IIS 设置完后,支持PHP。但是。连接数据库教程的时候。发现 undefined function mysql_connect() ,php教程.ini已经开启dll 了。DLL也复制到系统默认文件中了。但是事情还是如故!
 
 打开你安装目录的php.ini文件, ctrl+f搜索 将前面的";"php_mysql.dll
 
 将PHP.ini中以下几个参数前面的“;”去掉:
 ;extension=php_dba.dll
 ;extension=php_gd2.dll
 ;extension=php_mbstring.dll
 ;extension=php_mcrypt.dll
 ;extension=php_mysql.dll
 ;extension=php_mysqli.dll
 ;extension=php_pdo.dll
 ;extension=php_pdo_mysql.dll
 保存文件,重启IIS
 
 本文章原创于http://www.phprm.com 转载注明出处。

阅读全文

php 日期不全补0实例程序代码

 $time = '2010-1-11';
 
 //定义一个日间我相把把它变成2010-01-1
 
 $splitDate = explode("-",$time);
 
 //进行拆分以"-"分开
 
 $stime = mktime(0,0,0,$splitDate[1],$splitDate[2],$splitDate[0]);
 
 //再用mktime把它转换成时间载
 
 if( intval( $splitDate[1] )<10 && substr( $splitDate[1],0,1) !='0' )
 {
  $splitDate[1] = '0'.$splitDate[1];
 }
 //对月分取一个数字判断如果是01这种格式就不操作反之就加个0
 
 if( intval( $splitDate[2] )<10 && substr( $splitDate[2],0,1) !='0' )
 {
  $splitDate[2] = '0'.$splitDate[2];
 }
 //对日期作同样的作了,小于10就补0
 
 /*
  函数分析:
   explode 使用一个字符串分割另一个字符串 array explode ( string separator, string string [, int limit] )
   <a href=/phper/21/101d7c9a91356a428c8039c03dd4500b.htm>mktime</a>  函数返回一个日期的 Unix 时间戳。 mktime(hour,minute,second,month,day,year,is_dst)
   <a href=/phper/18/9351c693420d88336920eb2c12fca245.htm>intval</a> int intval ( mixed var [, int base])
通过使用特定的进制转换(默认是十进制),返回变量 var 的 integer 数值。

阅读全文

PHP文件 Zip 压缩与zip解压


/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;

阅读全文

php 列出目录与删除目录实例代码

function destroyDir($dir, $virtual = false)
{
$ds = DIRECTORY_SEPARATOR;
$dir = $virtual ? realpath($dir) : $dir;
$dir = substr($dir, -1) == $ds ? substr($dir, 0, -1) : $dir;
if (is_dir($dir) && $handle = opendir($dir))
{
while ($file = readdir($handle))
{
if ($file == '.' || $file == '..')
{
continue;
}
elseif (is_dir($dir.$ds.$file))
{
destroyDir($dir.$ds.$file);
}
else
{
unlink($dir.$ds.$file);
}
}
closedir($handle);
rmdir($dir);
return true;
}
else
{
return false;
}
}

阅读全文

php随机生成字符串与随机读取字符串

function readable_random_string($length = 6){
$conso=array("b","c","d","f","g","h","j","k","l",
"m","n","p","r","s","t","v","w","x","y","z");
$vocal=array("a","e","i","o","u");
$password="";
srand ((double)microtime()*1000000);
$max = $length/2;
for($i=1; $i<=$max; $i++)
{
$password.=$conso[rand(0,19)];
$password.=$vocal[rand(0,4)];
}
return $password;
}

阅读全文

php 字符操作类实例函数


class String extends stdClass
{
private $_val ='';
public function __construct( $str ='' )
{
$this->_val = $str;
}
public function __toString()
{
return $this->_val;
}
public function encode( $coder )
{
$coder ='encode_' . $coder;
if( method_exists( $this, $coder ) )
{
return $this->$coder();
}else{
return $this;
}
}
public function decode( $coder )
{
$coder ='decode_' . $coder;
if( method_exists( $this, $coder ) )
{
return $this->$coder();
}else{
return $this;
}
}
private function encode_md5()
{
return new String( md5( $this->_val ) );
}
private function decode_gbk()
{
return new String( iconv('GBK','UTF-8', $this->_val ) );
}
}

阅读全文

ajax无刷新更新数据

<table class="table_list" >

 <caption>
 填写要更新的数据
 </caption>
 
 <tr>
   <td class="align_c">无刷新保存</td>
   <td >
     <label>
     <input name="ajaxdata" type="text" size="20"  id="ajaxdata"/>
    &nbsp;</label></td>
  </tr>
 <tr>
   <td width="29%" class="align_c">&nbsp;</td>
   <td width="71%" ><label>
     <input type="submit" name="button"  onclick="return save();" value="提交" />
     &nbsp;&nbsp;&nbsp;

阅读全文