function sms_deal($mobile,$content){ //if(!Utility::IsMobile(trim($mobile))) exit; $count_str = getStringLength($content); $num_str_sms = (1*$count_str)/67;//短信按照每条67个字计算 $table = new Table('smslog'); $table->mobile = trim($mobile); $table->smslog = trim($content); $table->number = ceil($num_str_sms); $table->sms_time = strtotime('now'); $insert = $table->Insert(array('mobile', 'smslog', 'number','sms_time')); return $insert; }
/** * Trims the given string to a particular length. Does plain trimming. * * @param string $str Input string * @param int $trimLength Desired length * @param bool $nbsp Convert spaces to html entity * @param bool $hellip Replace the trimmed part with dots * @return array Array with two keys: 'string' and 'length' */ function trimString($str, $trimLength, $nbsp = false, $hellip = true) { $strLength = getStringLength($str); if ($strLength > $trimLength) { $str = mb_substr($str, 0, $trimLength, "UTF-8"); $resultingLength = $trimLength; if ($hellip) { $str .= '…'; } } else { $resultingLength = $strLength; } if ($nbsp == true) { $str = str_replace(" ", " ", $str); } return array('string' => $str, 'length' => $resultingLength); }
} $content = $fa['logContent']; $content_index = ""; if (empty($fa['password'])) { //加密日志不成生静态文件。 //生成首页文件 if (strpos($content, "<!--more-->") > 0) { $content_index = htmlSubString($content, "<!--more-->"); $content_index = formatBlogContent($content_index, 0, $fa['id'], 1); if ($fa['logsediter'] == "ubb") { $content_index = nl2br($content_index); } $content_index .= "<p><a class=\"more\" href=\"{$gourl}" . $fa['id'] . $settingInfo['stype'] . "\">[{$strContentAll}]</a></p> \n"; } else { if ($fa['autoSplit'] > 0) { $textlength = getStringLength(strip_tags($content)); if ($textlength > $fa['autoSplit']) { $content_index = htmlSubString($content, $fa['autoSplit']); $content_index = formatBlogContent($content_index, 0, $fa['id'], 1); if ($fa['logsediter'] == "ubb") { $content_index = nl2br($content_index); } $content_index .= "<p><a class=\"more\" href=\"{$gourl}" . $fa['id'] . $settingInfo['stype'] . "\">[{$strContentAll}]</a></p> \n"; } else { $content_index = htmlSubString($content, $fa['autoSplit']); $content_index = formatBlogContent($content_index, 0, $fa['id'], 1); if ($fa['logsediter'] == "ubb") { $content_index = nl2br($content_index); } } }
function htmlSubString($content, $maxlen = 300) { //把字符按HTML标签变成数组。 $content = preg_split("/(<[^>]+?>)/si", $content, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $wordrows = 0; //中英字数 $outstr = ""; //生成的字串 $wordend = false; //是否符合最大的长度 $beginTags = 0; //除<img><br><hr>这些短标签外,其它计算开始标签,如<div*> $endTags = 0; //计算结尾标签,如</div>,如果$beginTags==$endTags表示标签数目相对称,可以退出循环。 //print_r($content); foreach ($content as $value) { if (trim($value) == "") { continue; } //如果该值为空,则继续下一个值 if (strpos(";{$value}", "<") > 0) { //如果与要载取的标签相同,则到处结束截取。 if (trim($value) == $maxlen) { $wordend = true; continue; } if ($wordend == false) { $outstr .= $value; if (!preg_match("/<img([^>]+?)>/is", $value) && !preg_match("/<param([^>]+?)>/is", $value) && !preg_match("/<!([^>]+?)>/is", $value) && !preg_match("/<br([^>]+?)>/is", $value) && !preg_match("/<hr([^>]+?)>/is", $value)) { $beginTags++; //除img,br,hr外的标签都加1 } } else { if (preg_match("/<\\/([^>]+?)>/is", $value, $matches)) { $endTags++; $outstr .= $value; if ($beginTags == $endTags && $wordend == true) { break; } //字已载完了,并且标签数相称,就可以退出循环。 } else { if (!preg_match("/<img([^>]+?)>/is", $value) && !preg_match("/<param([^>]+?)>/is", $value) && !preg_match("/<!([^>]+?)>/is", $value) && !preg_match("/<br([^>]+?)>/is", $value) && !preg_match("/<hr([^>]+?)>/is", $value)) { $beginTags++; //除img,br,hr外的标签都加1 $outstr .= $value; } } } } else { if (is_numeric($maxlen)) { //截取字数 $curLength = getStringLength($value); $maxLength = $curLength + $wordrows; if ($wordend == false) { if ($maxLength > $maxlen) { //总字数大于要截取的字数,要在该行要截取 $outstr .= subString($value, 0, $maxlen - $wordrows); $wordend = true; } else { $wordrows = $maxLength; $outstr .= $value; } } } else { if ($wordend == false) { $outstr .= $value; } } } } //循环替换掉多余的标签,如<p></p>这一类 while (preg_match("/<([^\\/][^>]*?)><\\/([^>]+?)>/is", $outstr)) { $outstr = preg_replace_callback("/<([^\\/][^>]*?)><\\/([^>]+?)>/is", "strip_empty_html", $outstr); } //把误换的标签换回来 if (strpos(";" . $outstr, "[html_") > 0) { $outstr = str_replace("[html_<]", "<", $outstr); $outstr = str_replace("[html_>]", ">", $outstr); } //echo htmlspecialchars($outstr); return $outstr; }