<img src="http://www.gravatar.com/avatar.PHP?gravatar_id='.md5($email).
'&default='.$default.'&size='.$size.'&rating='.$rating.'" width="'.$size.'px"
height="'.$size.'px" />';
}
15. 在字符断点处截断文字 所谓断字 (word break),即一个单词可在转行时断开的地方。这一函数将在断字处截断字符串。
<div class="codetitle"><a style="CURSOR: pointer" data="9822" class="copybut" id="copybut9822" onclick="doCopy('code9822')"> 代码如下:<div class="codebody" id="code9822">
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
function myTruncate($string,$limit,$break=".",$pad="...") {
// return with no change if string is shorter than $limit
if(strlen($string) <= $limit)
return $string; // is $break present between $limit and the end of the string?
if(false !== ($breakpoint = strpos($string,$break,$limit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string,$breakpoint) . $pad;
}
}
return $string;
}
/* Example /
$short_string=myTruncate($long_string,100,' ');
16. 文件 Zip 压缩
<div class="codetitle"><a style="CURSOR: pointer" data="37334" class="copybut" id="copybut37334" onclick="doCopy('code37334')"> 代码如下:<div class="codebody" id="code37334">
/ 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; //close the zip -- done!
$zip->close(); //check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}
/*