本文整理汇总了PHP中mb_substr函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_substr函数的具体用法?PHP mb_substr怎么用?PHP mb_substr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mb_substr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xmt_cch_get
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'];
}
示例2: subtex1t4Question1
function subtex1t4Question1($text, $length)
{
if (mb_strlen($text, 'utf8') > $length) {
return mb_substr($text, 0, $length, 'utf8') . '...';
}
return $text;
}
示例3: smarty_modifier_truncate
/**
* 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;
}
示例4: action_repass
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');
}
}
示例5: toTitleCase
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));
}
示例6: index
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();
}
示例7: test_encoding
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";
}
}
}
示例8: on_index
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');
}
示例9: the_excerpt_max_charlength_page
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;
}
示例10: publish
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();
}
}
示例11: b_mylinks_random_show
/**
* 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;
}
示例12: getOrderTxt
/**
* 取得一个订单的输出 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;
}
示例13: dumpTokenEnd
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;
}
示例14: GetEndScript
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;
}
示例15: renderMe
public function renderMe($value)
{
if (strlen($value) > 70) {
$value = mb_substr($value, 0, 70, 'UTF-8') . ' ...';
}
return $this->extraHtmlBefore . $value . $this->extraHtmlAfter;
}