function xmt_cch_get($acc, $pth, $epr = 0) { global $xmt_acc; if (!$xmt_acc[$acc]['cfg']['cch_enb']) { return false; } $cch_fle = xmt_cch_dir . $acc . '-' . $pth . '.cch.php'; if (!file_exists($cch_fle)) { return false; } $cch_dat = mb_substr(@file_get_contents($cch_fle), 52); if (!$cch_dat) { return false; } $cch_dat = @json_decode($cch_dat, true); if (!$cch_dat) { return false; } $tme_spn = time() - intval($cch_dat['dte']); if ($epr == 0 && intval($xmt_acc[$acc]['cfg']['cch_exp']) > 0) { if ($tme_spn > intval($xmt_acc[$acc]['cfg']['cch_exp']) * 60) { return false; } } elseif ($epr > 0 && $tme_spn > $epr * 60) { return false; } return $cch_dat['dat']; }
function subtex1t4Question1($text, $length) { if (mb_strlen($text, 'utf8') > $length) { return mb_substr($text, 0, $length, 'utf8') . '...'; } return $text; }
/** * Smarty truncate modifier plugin * Type: modifier<br> * Name: truncate<br> * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string or inserting $etc into the middle. * * @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * * @param string $string input string * @param integer $length length of truncated text * @param string $etc end string * @param boolean $break_words truncate at word boundary * @param boolean $middle truncate in the middle of text * * @return string truncated string */ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { if ($length == 0) { return ''; } if (Smarty::$_MBSTRING) { if (mb_strlen($string, Smarty::$_CHARSET) > $length) { $length -= min($length, mb_strlen($etc, Smarty::$_CHARSET)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET)); } if (!$middle) { return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc; } return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, -$length / 2, $length, Smarty::$_CHARSET); } return $string; } // no MBString fallback if (isset($string[$length])) { $length -= min($length, strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1)); } if (!$middle) { return substr($string, 0, $length) . $etc; } return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2); } return $string; }
public function action_repass($onepass) { if (!Model_User::count(array('where' => array('onepass' => $onepass)))) { Response::redirect('user/login/without'); } if (Input::method() == 'POST') { $val = Model_User::validate('repass'); $val->add_field('email', 'Eメール', 'required|valid_email'); if ($val->run()) { $user = Model_User::find('first', array('where' => array('onepass' => $onepass))); $last_login = mb_substr($user['last_login'], -4); $reset = Input::post('reset'); if ($last_login == $reset) { $username = Input::post('username'); $email = Input::post('email'); $password = Input::post('password'); if ($username == $user['username'] && $email == $user['email']) { $user->onepass = md5(time()); $user->save(); $auth = Auth::instance(); $old = $auth->reset_password($username); $auth->change_password($old, $password, $username); Response::redirect('user/login'); } else { Session::set_flash('na', '<p><span class="alert-error">該当者がいません</span></p>'); } } else { Session::set_flash('error', "<p>" . $val->show_errors() . "</p>"); } } return Model_User::theme('admin/template', 'user/login/repass'); } }
private static function toTitleCase($str) { if (mb_strlen($str) === 0) { return $str; } return mb_strtoupper(mb_substr($str, 0, 1)) . mb_strtolower(mb_substr($str, 1)); }
protected function index($setting) { $this->load->model('bossblog/article'); if (file_exists('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/bossthemes/bossblog.css')) { $this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/bossthemes/bossblog.css'); } else { $this->document->addStyle('catalog/view/theme/default/stylesheet/bossthemes/bossblog.css'); } $results = array(); $results_data = $this->model_bossblog_article->getRecentCommentArticles($setting['limit']); $this->data['heading_title'] = $setting['title'][$this->config->get('config_language_id')]; $this->data['articles'] = array(); foreach ($results_data as $data) { $author = $data['author']; $comment = mb_substr(strip_tags(html_entity_decode($data['text'], ENT_QUOTES, 'UTF-8')), 0, 50) . '...'; $date_added = $data['date_added']; $result = $this->model_bossblog_article->getArticle($data['blog_article_id']); $this->data['articles'][] = array('blog_article_id' => $result['blog_article_id'], 'name' => $result['name'], 'author' => $author, 'comment' => $comment, 'date_added' => $date_added, 'href' => $this->url->link('bossblog/article', 'blog_article_id=' . $result['blog_article_id'])); } $this->data['template'] = $this->config->get('config_template'); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/blogrecentcomment.tpl')) { $this->template = $this->config->get('config_template') . '/template/module/blogrecentcomment.tpl'; } else { $this->template = 'default/template/module/blogrecentcomment.tpl'; } $this->render(); }
function test_encoding($path) { static $ur_exclude = array('lang/de/ocstyle/search1/search.result.caches', 'lib2/b2evo-captcha', 'lib2/HTMLPurifier', 'lib2/html2text.class.php', 'lib2/imagebmp.inc.php', 'lib2/Net/IDNA2', 'lib2/smarty'); $contents = file_get_contents($path, false, null, 0, 2048); $ur = stripos($contents, "Unicode Reminder"); if ($ur) { if (mb_trim(mb_substr($contents, $ur + 17, 2)) != "メモ") { $ur = mb_stripos($contents, "Unicode Reminder"); if (mb_trim(mb_substr($contents, $ur + 17, 2)) != "メモ") { echo "Bad Unicode Reminder found in {$path}: " . mb_trim(mb_substr($contents, $ur + 17, 2)) . "\n"; } else { echo "Unexpected non-ASCII chars (BOMs?) in header of {$path}\n"; } } } else { $ok = false; foreach ($ur_exclude as $exclude) { if (mb_strpos($path, $exclude) === 0) { $ok = true; } } if (!$ok) { echo "No Unicode Reminder found in {$path}\n"; } } }
public function on_index($category_id = 1, $goods_id = 0) { // 商品分类信息 $category = $this->db->where('status', 1)->order_by('location', 'asc')->result('category'); $this->view->assign('category', json_encode($category)); // 商品信息 $goods_rows = $this->db->where('status', 1)->result('goods'); $goods = array(); foreach ($goods_rows as $k => $i) { $i['image'] = IMAGED . $i['image']; $i['thumb'] = IMAGED . $i['thumb']; $i['goods_name'] = mb_substr($i['goods_name'], 0, 10, 'utf-8'); //先删除再添加 $goods[$i['goods_id']] = $i; } unset($goods_rows); // echo "<pre>"; // var_dump($goods);exit; $this->view->assign('goods', json_encode($goods)); // 收货人信息 $order_info = $this->db->where('user_id', $this->user_id)->order_by('create_time', 'desc')->row('order'); $consignee = array('username' => isset($order_info['username']) ? $order_info['username'] : '', 'mobile' => isset($order_info['mobile']) ? $order_info['mobile'] : '', 'city' => isset($order_info['city']) ? $order_info['city'] : '', 'area' => isset($order_info['area']) ? $order_info['area'] : '', 'address' => isset($order_info['address']) ? $order_info['address'] : '', 'delivery_times' => isset($order_info['delivery_times']) ? $order_info['delivery_times'] : '', 'payment_model' => isset($order_info['payment_model']) ? $order_info['payment_model'] : '', 'invoice' => isset($order_info['invoice']) ? $order_info['invoice'] : ''); $this->view->assign('consignee', json_encode($consignee)); // 用户信息 $userinfo = $this->db->where('user_id', $this->user_id)->row('user'); $user = array('user_id' => isset($userinfo['user_id']) ? $userinfo['user_id'] : '', 'mobile' => isset($userinfo['mobile']) ? $userinfo['mobile'] : '', 'email' => isset($userinfo['email']) ? $userinfo['email'] : '', 'amount' => isset($userinfo['amount']) ? $userinfo['amount'] : '', 'score' => isset($userinfo['score']) ? $userinfo['score'] : '', 'nickname' => isset($userinfo['nickname']) ? $userinfo['nickname'] : '', 'sex' => isset($userinfo['sex']) ? $userinfo['sex'] : ''); $this->view->assign('user', json_encode($user)); $this->view->assign('category_id', $category_id); $this->view->assign('goods_id', $goods_id); $this->view->display('goods/goods_index.html'); }
function the_excerpt_max_charlength_page($postid, $charlength) { $my_postid = $postid; //This is page id or post id $content_post = get_post($my_postid); $excerpt = $content_post->post_content; $excerpt = apply_filters('the_content', $excerpt); $excerpt = str_replace(']]>', ']]>', $excerpt); //$excerpt = get_field('descripcion', $postid); $charlength++; $return = ""; if (mb_strlen($excerpt) > $charlength) { $subex = mb_substr($excerpt, 0, $charlength - 5); $exwords = explode(' ', $subex); $excut = -mb_strlen($exwords[count($exwords) - 1]); if ($excut < 0) { $return .= mb_substr($subex, 0, $excut); } else { $return .= $subex; } $return .= '[...]'; } else { $return .= $excerpt; } return $return; }
public function publish($content, $uid, $reid = 0) { if (mb_strlen($content) > 255) { $data = array('content' => mb_substr($content, 0, 255, 'utf8'), 'content_over' => mb_substr($content, 255, 25, 'utf8')); } else { $data = array('content' => $content); } $data['ip'] = get_client_ip(1); $data['uid'] = $uid; if ($reid > 0) { $data['reid'] = $reid; } if ($this->create($data)) { $tid = $this->add(); if ($tid) { if ($reid > 0) { $this->setRecount($reid); } return $tid; } else { return 0; } } else { return $this->getError(); } }
/** * Mylinks Random Term Block * * Xoops Mylinks - a links module * * You may not change or alter any portion of this comment or credits * of supporting developers from this source code or any supporting source code * which is considered copyrighted (c) material of the original comment or credit authors. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * @copyright:: © The XOOPS Project http://sourceforge.net/projects/xoops/ * @license:: http://www.fsf.org/copyleft/gpl.html GNU public license * @package:: mylinks * @subpackage:: blocks * @author:: hsalazar * @author:: zyspec (owners@zyspec) * @version:: $Id$ * @since:: File available since Release 3.11 */ function b_mylinks_random_show() { global $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsUser; $mylinksDir = basename(dirname(dirname(__FILE__))); xoops_load('mylinksUtility', $mylinksDir); $myts =& MyTextSanitizer::getInstance(); $block = array(); $result = $xoopsDB->query("SELECT l.lid, l.cid, l.title, l.url, l.logourl, l.status, l.date, l.hits, l.rating, l.votes, l.comments, t.description FROM " . $xoopsDB->prefix("mylinks_links") . " l, " . $xoopsDB->prefix("mylinks_text") . " t WHERE l.lid=t.lid AND status>0 ORDER BY RAND() LIMIT 0,1"); if ($result) { list($lid, $cid, $ltitle, $url, $logourl, $status, $time, $hits, $rating, $votes, $comments, $description) = $xoopsDB->fetchRow($result); $link = $myts->displayTarea(ucfirst($ltitle)); $description = $myts->displayTarea(mb_substr($description, 0, 100)) . "..."; $mylinksCatHandler = xoops_getmodulehandler('category', $mylinksDir); $catObj = $mylinksCatHandler->get($cid); if (is_object($catObj) && !empty($catObj)) { $categoryName = $catObj->getVar('title'); $categoryName = $myts->displayTarea($categoryName); } else { $cid = 0; $categoryName = ''; } $block['title'] = _MB_MYLINKS_RANDOMTITLE; $block['content'] = "<div style=\"font-size: 12px; font-weight: bold; background-color: #ccc; padding: 4px; margin: 0;\"><a href=\"" . XOOPS_URL . "/modules/{$mylinksDir}/category.php?cid={$cid}\">{$categoryName}</a></div>"; $block['content'] .= "<div style=\"padding: 4px 0 0 0; color: #456;\"><h5 style=\"margin: 0;\"><a href=\"" . XOOPS_URL . "/modules/{$mylinksDir}/entry.php?lid={$lid}\">{$link}</a></h5><div>{$description}</div>"; unset($catObj, $mylinksCatHandler); $block['content'] .= "<div style=\"text-align: right; font-size: x-small;\"><a href=\"" . XOOPS_URL . "/modules/{$mylinksDir}/index.php\">" . _MB_MYLINKS_SEEMORE . "</a></div>"; } return $block; }
/** * 取得一个订单的输出 Txt * * */ private function getOrderTxt($orderReferInfo, $orderGoodsArray) { $retTxt = ''; $orderGoodsNameStr = ''; $coupon = $orderReferInfo['surplus'] + $orderReferInfo['bonus']; // 商品总价 $orderAmount = $orderReferInfo['goods_amount'] - $orderReferInfo['discount'] - $orderReferInfo['extra_discount'] - $orderReferInfo['refund']; // 商品总的额外退款金额 $orderExtraRefund = 0; // 订单状态 $orderStatus = 'refund'; switch ($orderReferInfo['pay_status']) { case OrderBasicService::PS_UNPAYED: $orderStatus = 'unpay'; break; case OrderBasicService::PS_PAYED: $orderStatus = 'pay'; break; default: $orderStatus = 'refund'; } // 对订单中每个商品单独计算 foreach ($orderGoodsArray as $orderGoodsItem) { $orderGoodsNameStr .= '{(' . $orderGoodsItem['goods_id'] . ')' . $orderGoodsItem['goods_name'] . '[' . $orderGoodsItem['goods_number'] . ' 件]},'; if (OrderGoodsService::OGS_UNPAY != $orderGoodsItem['order_goods_status'] && OrderGoodsService::OGS_PAY != $orderGoodsItem['order_goods_status']) { // 有一个 order_goods 是退款状态,整个订单就是退款状态 $orderStatus = 'refund'; } // 累计额外退款的总金额 $orderExtraRefund += $orderGoodsItem['extra_refund']; } $orderGoodsNameStr = str_replace('|', '_', $orderGoodsNameStr); $orderGoodsNameStr = mb_substr($orderGoodsNameStr, 0, 240); $referParamArray = json_decode($orderReferInfo['refer_param'], true); // CPS 应付总价 $orderAmountOfCps = $orderAmount - $coupon - $orderExtraRefund; $orderAmountOfCps = $orderAmountOfCps > 0 ? $orderAmountOfCps : 0; // QQ订单要多输出一条记录 if ('qqlogin' == $orderReferInfo['login_type']) { // 取得QQ登陆用户的信息 static $userBasicService = null; if (null == $userBasicService) { $userBasicService = new UserBasicService(); } $userInfo = $userBasicService->loadUserById($orderReferInfo['user_id']); //取得 QQ 用户的 openId ,QQ登陆的用户 sns_login 例子 qq:476BA0B2332440759D485548637DFCDD $qqUserOpenId = $userInfo->sns_login; $qqUserOpenId = substr($qqUserOpenId, strpos($qqUserOpenId, ':') + 1); //输出 QQ 登陆的记录 $retTxt .= $referParamArray['wi'] . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['add_time'])) . "||" . $orderReferInfo['order_id'] . "||" . Money::toSmartyDisplay($orderAmountOfCps) . "||" . $orderGoodsNameStr . "||" . $orderStatus . "||" . $orderStatus . "||alipay" . "||" . Money::toSmartyDisplay($orderReferInfo['shipping_fee']) . "||" . Money::toSmartyDisplay($coupon) . "||0" . "||" . $qqUserOpenId . "||" . 'bangzhufu' . "||" . 'qqlogin003' . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['update_time'])) . "\n"; } if ('YIQIFACPS' != $orderReferInfo['utm_source']) { // 不是亿起发的订单 goto out; } //输出 亿起发 的订单记录 $retTxt .= $referParamArray['wi'] . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['add_time'])) . "||" . $orderReferInfo['order_id'] . "||" . Money::toSmartyDisplay($orderAmountOfCps) . "||" . $orderGoodsNameStr . "||" . $orderStatus . "||" . $orderStatus . "||alipay" . "||" . Money::toSmartyDisplay($orderReferInfo['shipping_fee']) . "||" . Money::toSmartyDisplay($coupon) . "||0" . "||" . "||" . "||" . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['update_time'])) . "\n"; out: return $retTxt; }
function dumpTokenEnd($t, $canceled = false) { if ($this->token[0] !== $t[0]) { $this->setError(sprintf("Token has mutated from %s to %s", self::getTokenName($this->token[0]), self::getTokenName($t[0])), E_USER_WARNING); } $w = $this->codeWidth; $p = $this->placeholders; if (strlen($this->token[1]) > $w && mb_strlen($this->token[1], $this->encoding) > $w) { $this->token[1] = mb_substr($this->token[1], 0, $w - 1, $this->encoding) . $p[0]; } if ($canceled) { $t[1] = ' --- canceled --- '; $canceled = self::getTokenName($t[0]); } else { if (strlen($t[1]) > $w && mb_strlen($t[1], $this->encoding) > $w) { $t[1] = mb_substr($t[1], 0, $w - 1, $this->encoding) . $p[0]; } $canceled = ''; $s = array_slice($t[2], 1); foreach ($s as $s) { $canceled .= self::getTokenName($s) . ', '; } '' !== $canceled && ($canceled = substr($canceled, 0, -2)); } $w = array($w, $this->token[1], $w, $this->token[1] !== $t[1] ? '' === trim($t[1]) ? '' === $t[1] ? $p[1] : str_replace(' ', $p[2], $t[1]) : $t[1] : ''); $w[0] += strlen($w[1]) - mb_strlen($w[1], $this->encoding); $w[2] += strlen($w[3]) - mb_strlen($w[3], $this->encoding); echo str_replace(array("\r\n", "\n", "\r"), array($p[3], $p[3], $p[3]), sprintf("% 4s % {$w[0]}s % -{$w[2]}s %s", $this->token['line'], $w[1], $w[3], $canceled)) . "\n"; $this->token = null; }
public function GetEndScript() { $strToReturn = parent::GetEndScript(); if (QDateTime::$Translate) { $strShortNameArray = array(); $strLongNameArray = array(); $strDayArray = array(); $dttMonth = new QDateTime('2000-01-01'); for ($intMonth = 1; $intMonth <= 12; $intMonth++) { $dttMonth->Month = $intMonth; $strShortNameArray[] = '"' . $dttMonth->ToString('MMM') . '"'; $strLongNameArray[] = '"' . $dttMonth->ToString('MMMM') . '"'; } $dttDay = new QDateTime('Sunday'); for ($intDay = 1; $intDay <= 7; $intDay++) { $strDay = $dttDay->ToString('DDD'); $strDay = html_entity_decode($strDay, ENT_COMPAT, QApplication::$EncodingType); if (function_exists('mb_substr')) { $strDay = mb_substr($strDay, 0, 2); } else { // Attempt to account for multibyte day -- may not work if the third character is multibyte $strDay = substr($strDay, 0, strlen($strDay) - 1); } $strDay = QApplication::HtmlEntities($strDay); $strDayArray[] = '"' . $strDay . '"'; $dttDay->Day++; } $strArrays = sprintf('new Array(new Array(%s), new Array(%s), new Array(%s))', implode(', ', $strLongNameArray), implode(', ', $strShortNameArray), implode(', ', $strDayArray)); $strToReturn .= sprintf('qc.regCAL("%s", "%s", "%s", "%s", %s); ', $this->strControlId, $this->dtxLinkedControl->ControlId, QApplication::Translate('Today'), QApplication::Translate('Cancel'), $strArrays); } else { $strToReturn .= sprintf('qc.regCAL("%s", "%s", "%s", "%s", null); ', $this->strControlId, $this->dtxLinkedControl->ControlId, QApplication::Translate('Today'), QApplication::Translate('Cancel')); } return $strToReturn; }
public function renderMe($value) { if (strlen($value) > 70) { $value = mb_substr($value, 0, 70, 'UTF-8') . ' ...'; } return $this->extraHtmlBefore . $value . $this->extraHtmlAfter; }
/** * Définir un cookie avec le contenu de paramètres transmis en GET puis rappeler la page * * @param string $query_string éventuellement avec 'url_redirection' en dernier paramètre * @return void */ public static function save_get_and_exit_reload( $query_string ) { Cookie::definir( COOKIE_MEMOGET , $query_string , 300 /* 60*5 = 5 min */ ); $param_redir_pos = mb_strpos($query_string,'&url_redirection'); $param_sans_redir = ($param_redir_pos) ? mb_substr( $query_string , 0 , $param_redir_pos ) : $query_string ; // J'ai déjà eu un msg d'erreur car il n'aime pas les chaines trop longues + Pas la peine d'encombrer avec le paramètre de redirection qui sera retrouvé dans le cookie de toutes façons exit_redirection(URL_BASE.$_SERVER['SCRIPT_NAME'].'?'.$param_sans_redir); }
function _substr($string, $start, $length) { if ($this->is_overloaded) { return mb_substr($string,$start,$length,'ascii'); } else { return substr($string,$start,$length); } }
public function index() { $url = get_url(); //获取当前页面的URL地址 $memb = M('Member'); if (IS_POST) { $idarr = I('post.idarr'); $where = array('vip_id' => array('in', $idarr)); $res = $memb->where($where)->delete(); if ($res) { echo "<script>window.location.href=" . $url . ";</script>"; } else { echo "<script>alert('删除失败');window.history.go(-1);</script>"; } } $current = I('get.page', 1); $limit = 20; $art = ($current - 1) * $limit; $fir = strpos($url, 'page'); if ($fir) { $purl = mb_substr($url, 0, $fir - 1); } else { $purl = $url; } $count = $memb->count(); $show = list_page($current, $limit, $count, $purl); $vip = $memb->order('vip_addtime DESC')->limit($art, $limit)->select(); $data = array('vip' => $vip, 'show' => $show); $this->assign($data); $this->display(); }
function str_pad_unicode($str, $pad_len, $pad_str = ' ', $dir = STR_PAD_RIGHT) { $str_len = mb_strlen($str); $pad_str_len = mb_strlen($pad_str); if (!$str_len && ($dir == STR_PAD_RIGHT || $dir == STR_PAD_LEFT)) { $str_len = 1; // @debug } if (!$pad_len || !$pad_str_len || $pad_len <= $str_len) { return $str; } $result = null; $repeat = ceil($str_len - $pad_str_len + $pad_len); if ($dir == STR_PAD_RIGHT) { $result = $str . str_repeat($pad_str, $repeat); $result = mb_substr($result, 0, $pad_len); } else { if ($dir == STR_PAD_LEFT) { $result = str_repeat($pad_str, $repeat) . $str; $result = mb_substr($result, -$pad_len); } else { if ($dir == STR_PAD_BOTH) { $length = ($pad_len - $str_len) / 2; $repeat = ceil($length / $pad_str_len); $result = mb_substr(str_repeat($pad_str, $repeat), 0, floor($length)) . $str . mb_substr(str_repeat($pad_str, $repeat), 0, ceil($length)); } } } return $result; }
/** * Smarty truncate modifier plugin * * Type: modifier<br> * Name: truncate<br> * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string or inserting $etc into the middle. * * @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @param string $string input string * @param integer $length length of truncated text * @param string $etc end string * @param boolean $break_words truncate at word boundary * @param boolean $middle truncate in the middle of text * @return string truncated string */ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { if ($length == 0) { return ''; } if (SMARTY_MBSTRING && empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])) { if (mb_strlen($string, SMARTY_RESOURCE_CHAR_SET) > $length) { $length -= min($length, mb_strlen($etc, SMARTY_RESOURCE_CHAR_SET)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/u', '', mb_substr($string, 0, $length + 1, SMARTY_RESOURCE_CHAR_SET)); } if (!$middle) { return mb_substr($string, 0, $length, SMARTY_RESOURCE_CHAR_SET) . $etc; } return mb_substr($string, 0, $length / 2, SMARTY_RESOURCE_CHAR_SET) . $etc . mb_substr($string, -$length / 2, $length, SMARTY_RESOURCE_CHAR_SET); } return $string; } // no MBString fallback if (isset($string[$length])) { $length -= min($length, strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1)); } if (!$middle) { return substr($string, 0, $length) . $etc; } return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2); } return $string; }
private function obtener_tuits() { $search = "from%3Atelemedellin%20#NoticiasTM"; $notweets = 6; $consumerkey = "lvX5ZuwYkNNFwaYaLz0Rw"; $consumersecret = "tkEfo98Xcpg0rYphooAetOSVjBcYEXhM4pKTGh1Bw"; $accesstoken = "44186827-6qP8bJ2cRD5Hwkol6hJn782lzSEprym5tyVI4mAc5"; $accesstokensecret = "xI07T7D9S6E6jnEQ2muSYD1kSBIATRkGgKM3C6w"; $connection = Yii::app()->twitter->getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); $search = str_replace("#", "%23", $search); $tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=" . $search . "&count=" . $notweets); $nuevos_tweets = array(); if (!empty($tweets) && !empty($tweets->statuses)) { foreach ($tweets->statuses as $tweet) { if (substr($tweet->text, 0, 2) == 'RT') { continue; } $texto_original = $tweet->text; $texto_nuevo = ''; $ultimo_indice = 0; $entidades = array(); //print_r($tweet->entities);exit(); if (count($tweet->entities->hashtags)) { foreach ($tweet->entities->hashtags as $hashtag) { $nh = '<a href="https://twitter.com/search?q=%23NoticiasTM" target="_blank" rel="nofollow" title="Ver los tuits del Hashtag #NoticiasTM en Twitter"><s>#</s><b class="hashtag">' . $hashtag->text . '</b></a>'; $entidades[] = array('texto' => $nh, 'pi' => $hashtag->indices[0], 'pf' => $hashtag->indices[1]); } } if (count($tweet->entities->user_mentions)) { foreach ($tweet->entities->user_mentions as $user_mention) { $num = '<a href="https://twitter.com/' . $user_mention->screen_name . '" target="_blank" rel="nofollow" title="Ver el perfil del usuario ' . $user_mention->screen_name . ' en Twitter"><s>@</s><b class="user_mention">' . $user_mention->screen_name . '</b></a>'; $entidades[] = array('texto' => $num, 'pi' => $user_mention->indices[0], 'pf' => $user_mention->indices[1]); } } if (count($tweet->entities->urls)) { foreach ($tweet->entities->urls as $url) { $nu = '<a href="' . $url->expanded_url . '" target="_blank" rel="nofollow" class="tlink">' . $url->url . '</a>'; $entidades[] = array('texto' => $nu, 'pi' => $url->indices[0], 'pf' => $url->indices[1]); } } if (count($tweet->entities->media)) { foreach ($tweet->entities->media as $media) { $nm = '<a href="' . $media->expanded_url . '" target="_blank" rel="nofollow" class="tlink">' . $media->url . '</a>'; $entidades[] = array('texto' => $nm, 'pi' => $media->indices[0], 'pf' => $media->indices[1]); } } usort($entidades, "NewsTicker::ceo"); for ($i = 0; $i < count($entidades); $i++) { $pedazo = mb_substr($texto_original, $ultimo_indice, $entidades[$i]['pi'] - $ultimo_indice, 'UTF-8'); $texto_nuevo .= $pedazo; $texto_nuevo .= $entidades[$i]['texto']; $ultimo_indice = $entidades[$i]['pf']; } $texto_nuevo .= mb_substr($texto_original, $ultimo_indice, 200, 'UTF-8'); $nuevos_tweets[] = $texto_nuevo; } Yii::app()->cache->set('tweets', $nuevos_tweets, 300); } return $nuevos_tweets; }
public function __execute() { $array = array(); $data = $this->__verify(); //数据格参数 $param = array('pid' => $data['id'], 'pn' => $data['pn'], 'rn' => $data['rn']); //获取抽奖会员列表 $drawObject = $this->sPrize->prizeUserByCondition($param); //获取投注记录总数 $drawCount = $this->sPrize->getRecordCountByPid($data['id']); //保存处理结果 $drawList = array(); //格式化数据 if ($drawObject && count($drawObject) > 0) { foreach ($drawObject as $draw) { if (!empty($draw['prize_user_name']) && trim($draw['prize_user_name']) != '匿名' && trim($draw['prize_user_name']) == trim($draw['prize_user_mobile'])) { $draw['prize_user_name'] = '匿名'; } else { $draw['prize_user_name'] = mb_substr($draw['prize_user_name'], 0, 1, 'utf-8') . '**'; } if (!empty($draw['prize_user_mobile']) && strlen($draw['prize_user_mobile']) == 11) { $first = substr($draw['prize_user_mobile'], 0, 3); $last = substr($draw['prize_user_mobile'], 7, strlen($draw['prize_user_mobile'])); $draw['prize_user_mobile'] = $first . '****' . $last; } $draw['prize_user_pdate'] = date('Y-m-d H:i:s', $draw['prize_user_pdate']); $draw['prize_user_locat'] = $draw['prize_user_province'] . $draw['prize_user_city'] . $draw['prize_user_district']; $drawList[] = $draw; } } //返回并输出结果信息 return array('coun' => $drawCount, 'list' => $drawList, 'page' => Blue_Page::pageInfo($drawCount, $data['pn'], $data['rn'], 5)); }
public function read($count) { $this->ensureOpen(); $remainingCount = $count; $availableCount = $this->available(); if ($remainingCount <= $availableCount) { $readFromBuffer = $count; } else { $readFromBuffer = $availableCount; } $result = null; if ($readFromBuffer > 0) { $result = mb_substr($this->buffer, $this->position, $readFromBuffer); $this->position += $readFromBuffer; $remainingCount -= $readFromBuffer; } if ($remainingCount > 0) { $remaining = $this->in->read($remainingCount); if ($this->markPosition !== null) { $this->buffer .= $remaining; $remainingLength = mb_strlen($remaining); $this->bufferLength += $remainingLength; $this->position += $remainingLength; } if ($remaining !== null) { $result .= $remaining; } } return $result; }
private function showError($text) { $text = mb_substr($text, 20, mb_strlen($text, 'utf8'), 'utf8'); $text = explode('Stack trace:', $text); $text = $text[0]; return $text; }
/** * Smarty mb_truncate modifier plugin * * Type: modifier<br> * Name: mb_truncate<br> * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string. (MultiByte version) * @link http://smarty.php.net/manual/en/language.modifier.truncate.php * truncate (Smarty online manual) * @param string * @param string * @param integer * @param string * @param boolean * @return string */ function smarty_modifier_mb_truncate($string, $length = 80, $etc = '...', $break_words = false) { if ($length == 0) { return ''; } $string = str_replace("&", "&", $string); if (function_exists("mb_internal_encoding") && function_exists("mb_strlen") && function_exists("mb_substr")) { mb_internal_encoding("UTF8"); if (mb_strlen($string) > $length) { $length -= mb_strlen($etc); if (!$break_words) { $string = preg_replace('/\\s+?(\\S+)?$/', '', mb_substr($string, 0, $length + 1)); } $string = mb_substr($string, 0, $length) . $etc; } } else { //modifier.truncate if (strlen($string) > $length) { $length -= strlen($etc); if (!$break_words) { $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1)); } $string = substr($string, 0, $length) . $etc; } } $string = str_replace("&", "&", $string); return $string; }
/** * 日历课程接口 */ public function actionGetSubjectSchedule() { if (!isset($_REQUEST['teacherId']) || !isset($_REQUEST['token']) || !isset($_REQUEST['date'])) { $this->_return('MSG_ERR_LESS_PARAM'); } $user_id = trim(Yii::app()->request->getParam('teacherId', null)); $token = trim(Yii::app()->request->getParam('token', null)); $date = trim(Yii::app()->request->getParam('date', null)); if (!ctype_digit($user_id)) { $this->_return('MSG_ERR_FAIL_PARAM'); } // 用户名不存在,返回错误 if ($user_id < 1) { $this->_return('MSG_ERR_NO_USER'); } // 验证日期格式合法 if (!$this->isDate($date)) { $this->_return('MSG_ERR_FAIL_DATE_FORMAT'); } $year = mb_substr($date, 0, 4, 'utf8'); $month = mb_substr($date, 5, 2, 'utf8'); $day = mb_substr($date, 8, 2, 'utf8'); if (empty($year) || empty($month) || empty($day)) { $this->_return('MSG_ERR_FAIL_DATE_LESS'); } // 验证token if (Token::model()->verifyToken($user_id, $token)) { // 获取日历课程 $data = Lesson::model()->getSubjectSchedule($user_id, $year, $month, $day, $date); $this->_return('MSG_SUCCESS', $data); } else { $this->_return('MSG_ERR_TOKEN'); } }
/** * Smarty truncate modifier plugin * * Type: modifier<br> * Name: truncate<br> * Purpose: Truncate a string to a certain length if necessary, * optionally splitting in the middle of a word, and * appending the $etc string or inserting $etc into the middle. * * @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual) * @author Monte Ohrt <monte at ohrt dot com> * @param string $string input string * @param integer $length lenght of truncated text * @param string $etc end string * @param boolean $break_words truncate at word boundary * @param boolean $middle truncate in the middle of text * @return string truncated string */ function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { if ($length == 0) { return ''; } if (is_callable('mb_strlen')) { if (mb_strlen($string) > $length) { $length -= min($length, mb_strlen($etc)); if (!$break_words && !$middle) { $string = mb_ereg_replace('/\\s+?(\\S+)?$/', '', mb_substr($string, 0, $length + 1), 'p'); } if (!$middle) { return mb_substr($string, 0, $length) . $etc; } else { return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, -$length / 2); } } else { return $string; } } else { if (strlen($string) > $length) { $length -= min($length, strlen($etc)); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/', '', substr($string, 0, $length + 1)); } if (!$middle) { return substr($string, 0, $length) . $etc; } else { return substr($string, 0, $length / 2) . $etc . substr($string, -$length / 2); } } else { return $string; } } }
function mmstrlen($str) { $standalones = array("ဤ", "၍", "ဪ", "၏", "၊", "။", "၌"); $consonants = array("က", "ခ", "ဂ", "ဃ", "င", "စ", "ဆ", "ဇ", "ဈ", "ည", "ဍ", "ဌ", "ဋ", "ဎ", "ဏ", "တ", "ထ", "ဒ", "ဓ", "န", "ပ", "ဖ", "ဗ", "ဘ", "မ", "ယ", "ရ", "လ", "ဝ", "သ", "ဟ", "ဠ", "အ"); $numbers = array("၀", "၁", "၂", "၃", "၄", "၅", "၆", "၇", "၈", "၉"); $len = mb_strlen($str, "UTF-8"); $count = 0; for ($i = 0; $i < $len; $i++) { $char = mb_substr($str, $i, 1, "UTF-8"); if (!burmese($char)) { $count++; } else { if (in_array($char, $consonants) || in_array($char, $standalones) || in_array($char, $numbers) || $char == " ") { $count++; } if ($char == "်") { $prev = mb_substr($str, $i - 1, 1, "UTF-8"); if (in_array($prev, $consonants)) { $count--; } } } } return $count; }
function smarty_modifier_cut($string, $length = 80, $etc = '...', $break_words = false, $middle = false) { global $cfg; if ($length == 0) { return ''; } $string = preg_replace('/<[^>]*?>/', '', $string); $string = preg_replace('/ /', '', $string); $string = preg_replace('/"/', '"', $string); $string = preg_replace('/”/', '"', $string); $string = preg_replace('/“/', '"', $string); $string = preg_replace('/&[a-z]*;/', ' ', $string); $string = preg_replace('/\\s+/', '', $string); if (strlen($string) > $length) { $length -= strlen($etc); if (!$break_words && !$middle) { $string = preg_replace('/\\s+?(\\S+)?$/', '', mb_substr($string, 0, $length + 1, $cfg['mysql_charset'])); } if (!$middle) { return mb_substr($string, 0, $length, $cfg['mysql_charset']) . $etc; } else { return mb_substr($string, 0, $length / 2, $cfg['mysql_charset']) . $etc . mb_substr($string, -$length / 2, $cfg['mysql_charset']); } return mb_substr($string, 0, $length, $cfg['mysql_charset']) . $etc; } else { return $string; } }
/** * Retrieve the initial or submitted value. * * @return string * @param bool[optional] $allowHTML Is HTML allowed? */ public function getValue($allowHTML = null) { // redefine html & default value $allowHTML = $allowHTML !== null ? (bool) $allowHTML : $this->isHTML; $value = $this->value; // contains html if ($this->isHTML) { // set value $value = SPOON_CHARSET == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value); } // form submitted if ($this->isSubmitted()) { // post/get data $data = $this->getMethod(true); // submitted by post (may be empty) if (isset($data[$this->getName()])) { // value $value = $data[$this->attributes['name']]; // maximum length? if (isset($this->attributes['maxlength']) && $this->attributes['maxlength'] > 0) { $value = mb_substr($value, 0, (int) $this->attributes['maxlength'], SPOON_CHARSET); } // html allowed? if (!$allowHTML) { $value = SPOON_CHARSET == 'utf-8' ? SpoonFilter::htmlspecialchars($value) : SpoonFilter::htmlentities($value); } } } return $value; }