当前位置: 首页>>代码示例>>PHP>>正文


PHP mb_strcut函数代码示例

本文整理汇总了PHP中mb_strcut函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_strcut函数的具体用法?PHP mb_strcut怎么用?PHP mb_strcut使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mb_strcut函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getExtBySignature

 /**
  * Get file extension by file header signature.
  *
  * @param string $stream
  *
  * @return string
  */
 public static function getExtBySignature($stream)
 {
     $prefix = strval(bin2hex(mb_strcut($stream, 0, 10)));
     foreach (self::$signatures as $signature => $extension) {
         if (0 === strpos($prefix, strval($signature))) {
             return $extension;
         }
     }
     return '';
 }
开发者ID:sunmingyang,项目名称:wechat,代码行数:17,代码来源:File.php

示例2: get255ByteCacheTagHeaderStringValues

 /**
  * Generate list of X-Cache-Tag header values which are less than 255 bytes each
  *
  * @param $cacheTagList
  * @return array
  */
 public function get255ByteCacheTagHeaderStringValues($cacheTagList)
 {
     $cacheTagHeaderList = array();
     $cacheTagHeader = "";
     foreach ($cacheTagList as $cacheTag) {
         $cacheTagHeaderEncoding = mb_detect_encoding($cacheTagHeader);
         $cacheTagEncoding = mb_detect_encoding($cacheTag);
         //Is this cache tag larger than 255 bytes?
         if (mb_strlen($cacheTag, $cacheTagEncoding) >= 255) {
             array_push($cacheTagHeaderList, mb_strcut($cacheTag, 1, 255));
         } else {
             if (mb_strlen($cacheTagHeader, $cacheTagHeaderEncoding) + mb_strlen("," . $cacheTag, $cacheTagEncoding) > 255) {
                 //Start new header
                 array_push($cacheTagHeaderList, $cacheTagHeader);
                 $cacheTagHeader = $cacheTag;
             } else {
                 //Append cache tag to cache tag header
                 if ($cacheTagHeader !== "") {
                     //avoid creating headers that start with a comma.
                     $cacheTagHeader = $cacheTagHeader . ",";
                 }
                 $cacheTagHeader = $cacheTagHeader . $cacheTag;
             }
         }
     }
     array_push($cacheTagHeaderList, $cacheTagHeader);
     return $cacheTagHeaderList;
 }
开发者ID:cloudflare,项目名称:cloudflare-magento,代码行数:34,代码来源:CacheTags.php

示例3: add

 public function add()
 {
     $data['title'] = I('title', '未命名');
     $data['text'] = stripslashes($_POST['content']);
     $data['tid'] = I('tid', 1);
     $data['cid'] = I('cid', 1);
     $data['ispage'] = I('ispage', 1);
     $data['iscomment'] = I('iscomment', 1);
     $data['status'] = I('status', 1);
     $data['uid'] = session('ey_id');
     if ($_POST['abscontent']) {
         $data['abscontent'] = $_POST['abscontent'];
     } else {
         $data['abscontent'] = mb_strcut(strip_tags($_POST['content']), 0, 200, 'utf-8');
         //提取前200个字符
     }
     if ($_POST['id']) {
         $rs = M('contents')->where('id=' . $_POST['id'])->save($data);
     } else {
         $data['time'] = time();
         $rs = M('contents')->add($data);
     }
     if ($rs) {
         die(json_encode(array('status' => 1, 'msg' => '操作成功!')));
     } else {
         die(json_encode(array('status' => 0, 'msg' => '操作失败')));
     }
 }
开发者ID:ShelterYa,项目名称:easyou,代码行数:28,代码来源:ContentController.class.php

示例4: ignoreHtml

function ignoreHtml($html, $maxLength = 100)
{
    mb_internal_encoding("UTF-8");
    $printedLength = 0;
    $position = 0;
    $tags = array();
    $newContent = '';
    $html = $content = preg_replace("/<img[^>]+\\>/i", "", $html);
    while ($printedLength < $maxLength && preg_match('{</?([a-z]+)[^>]*>|&#?[a-zA-Z0-9]+;}', $html, $match, PREG_OFFSET_CAPTURE, $position)) {
        list($tag, $tagPosition) = $match[0];
        // Print text leading up to the tag.
        $str = mb_strcut($html, $position, $tagPosition - $position);
        if ($printedLength + mb_strlen($str) > $maxLength) {
            $newstr = mb_strcut($str, 0, $maxLength - $printedLength);
            $newstr = preg_replace('~\\s+\\S+$~', '', $newstr);
            $newContent .= $newstr;
            $printedLength = $maxLength;
            break;
        }
        $newContent .= $str;
        $printedLength += mb_strlen($str);
        if ($tag[0] == '&') {
            // Handle the entity.
            $newContent .= $tag;
            $printedLength++;
        } else {
            // Handle the tag.
            $tagName = $match[1][0];
            if ($tag[1] == '/') {
                // This is a closing tag.
                $openingTag = array_pop($tags);
                assert($openingTag == $tagName);
                // check that tags are properly nested.
                $newContent .= $tag;
            } else {
                if ($tag[mb_strlen($tag) - 2] == '/') {
                    // Self-closing tag.
                    $newContent .= $tag;
                } else {
                    // Opening tag.
                    $newContent .= $tag;
                    $tags[] = $tagName;
                }
            }
        }
        // Continue after the tag.
        $position = $tagPosition + mb_strlen($tag);
    }
    // Print any remaining text.
    if ($printedLength < $maxLength && $position < mb_strlen($html)) {
        $newstr = mb_strcut($html, $position, $maxLength - $printedLength);
        $newstr = preg_replace('~\\s+\\S+$~', '', $newstr);
        $newContent .= $newstr;
    }
    // Close any open tags.
    while (!empty($tags)) {
        $newContent .= sprintf('</%s>', array_pop($tags));
    }
    return $newContent . "...";
}
开发者ID:JozefAB,项目名称:neoacu,代码行数:60,代码来源:default.php

示例5: parseArgList

 private function parseArgList()
 {
     $currentKey = "";
     foreach ($this->rawArgs as $arg) {
         if ($arg[0] == "-") {
             if ($currentKey) {
                 $this->namedArgs[$currentKey] = "";
             }
             if ($arg[1] == "-") {
                 if (strpos($arg, "=")) {
                     list($currentKey, $value) = explode("=", $arg);
                     $this->namedArgs[$currentKey] = $value;
                     $currentKey = "";
                 } else {
                     $currentKey = $arg;
                 }
             } else {
                 $currentKey = mb_strcut($arg, 0, 2);
                 $value = mb_strcut($arg, 2);
                 $this->namedArgs[$currentKey] = $value;
                 $currentKey = "";
             }
         } else {
             if ($currentKey) {
                 $this->namedArgs[$currentKey] = $arg;
                 $currentKey = "";
             } else {
                 $this->listArgs[] = $arg;
             }
         }
     }
     if ($currentKey) {
         $this->namedArgs[$currentKey] = "";
     }
 }
开发者ID:mipxtx,项目名称:threadunit,代码行数:35,代码来源:ThreadUnit.php

示例6: cutStr

 public static function cutStr($str, $length, $add = '...')
 {
     if (mb_strlen($str) > $length) {
         $str = mb_strcut($str, 0, $length) . $add;
     }
     return $str;
 }
开发者ID:hellojo84,项目名称:99ko,代码行数:7,代码来源:util.class.php

示例7: serialize

 /**
  * Turns the object back into a serialized blob.
  *
  * @return string
  */
 public function serialize()
 {
     $str = $this->name;
     if ($this->group) {
         $str = $this->group . '.' . $this->name;
     }
     $src = array(';');
     $out = array(',');
     if (is_array($this->value)) {
         $this->value = implode(',', $this->value);
     }
     $value = strtr($this->value, array('\\,' => ',', '\\;' => ';'));
     $str .= ':' . str_replace($src, $out, $value);
     $out = '';
     while (strlen($str) > 0) {
         if (strlen($str) > 75) {
             $out .= mb_strcut($str, 0, 75, 'utf-8') . "\r\n";
             $str = ' ' . mb_strcut($str, 75, strlen($str), 'utf-8');
         } else {
             $out .= $str . "\r\n";
             $str = '';
             break;
         }
     }
     return $out;
 }
开发者ID:BacLuc,项目名称:newGryfiPage,代码行数:31,代码来源:stringpropertycategories.php

示例8: __call

 public function __call($attrName, $arguments)
 {
     if (preg_match('/^_render/', $attrName)) {
         $attrName = mb_strtolower(mb_strcut($attrName, 7));
         if (!empty($this->_options)) {
             $attrName = array_merge(array($attrName), $this->_options);
             $attrName = implode('_', $attrName);
         }
         $attrName = preg_replace('/[^\\w\\d-_]/ui', '', $attrName);
         // check if we have a getter for this property
         $getter = 'get' . ucfirst($attrName);
         if (method_exists($this->_user, $getter)) {
             $value = $this->_user->{$getter}();
         } else {
             // or try to get attribute value
             $value = $this->_user->getAttribute($attrName);
         }
         if ($this->_editableMode) {
             $this->_view->attribute = $attrName;
             $this->_view->value = $value;
             $this->_view->userId = $this->_user->getId();
             return $this->_view->render('user-attribute.phtml');
         }
         return $value;
     }
 }
开发者ID:PavloKovalov,项目名称:seotoaster,代码行数:26,代码来源:Base.php

示例9: randomName

 public function randomName()
 {
     $nameLib = ' 邦福歌国和康澜民宁平然顺翔晏宜怡易志昂然昂雄宾白宾鸿宾实彬彬彬炳彬郁斌斌斌蔚滨海波光波鸿波峻波涛博瀚博超博达博厚博简博明博容博赡博涉博实博涛博文博学博雅博延博艺博易博裕博远才捷才才艺才英才哲才俊成和成弘成化成济成礼成龙成仁成双成天成文成业成益成荫成周承承弼承德承恩承福承基承教承平承嗣承天承望承宣承颜承业承悦承允承运承载承泽承志德本德海德厚德华德辉德惠德容德润德寿德水德馨德曜德业德义德庸德佑德宇德元德运德泽德明昂白飙掣尘沉驰光翰航翮鸿虎捷龙鸾鸣鹏扬文翔星翼';
     $nameLibNum = (int) strlen($nameLib) / 3;
     $m = M('People');
     $havePeople = $m->count(1);
     while ($havePeople >= 0) {
         $havePeople--;
         if ($havePeople < 0) {
             break;
         }
         $namePos[0] = mb_strcut($nameLib, rand(0, $nameLibNum), 3, 'utf-8');
         $namePos[1] = mb_strcut($nameLib, rand(0, $nameLibNum), 3, 'utf-8');
         $namePos[2] = mb_strcut($nameLib, rand(0, $nameLibNum), 3, 'utf-8');
         $newName = $namePos[0] . $namePos[1] . $namePos[2];
         $origin = $m->limit($havePeople, 1)->field('name,pid')->select();
         dump($origin);
         $originName = $origin[0]['name'];
         $where['pid'] = $origin[0]['pid'];
         $result = $m->where($where)->setField('name', $newName);
         // dump($result);
         echo "{$originName} -> {$newName} ";
         if ($result === 1) {
             echo "OK <br> \n";
         } else {
             echo "X <br> \n";
         }
     }
 }
开发者ID:skingzd,项目名称:pms,代码行数:29,代码来源:SetupController.class.php

示例10: serialize

 /**
  * Turns the object back into a serialized blob.
  *
  * @return string
  */
 public function serialize()
 {
     $str = $this->name;
     if ($this->group) {
         $str = $this->group . '.' . $this->name;
     }
     foreach ($this->parameters as $param) {
         $str .= ';' . $param->serialize();
     }
     $src = array("\n");
     $out = array('\\n');
     $str .= ':' . str_replace($src, $out, $this->value);
     $out = '';
     while (strlen($str) > 0) {
         if (strlen($str) > 75) {
             $out .= mb_strcut($str, 0, 75, 'utf-8') . "\r\n";
             $str = ' ' . mb_strcut($str, 75, strlen($str), 'utf-8');
         } else {
             $out .= $str . "\r\n";
             $str = '';
             break;
         }
     }
     return $out;
 }
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:30,代码来源:compoundproperty.php

示例11: addItem

 /**
  * splits item into new lines if necessary
  * @param string $item
  * @return CalendarStream
  */
 public function addItem($item)
 {
     $lines = array();
     $parts = explode(PHP_EOL, trim($item));
     $top = array_shift($parts);
     $lines[] = $top;
     if (empty($parts) === false) {
         $lines[0] .= "\\n";
         foreach ($parts as $line) {
             $block = ' ';
             //get number of bytes
             $length = strlen($line);
             if ($length > 75) {
                 $start = 0;
                 while ($start < $length) {
                     $block .= mb_strcut($line, $start, self::LINE_LENGTH, 'UTF-8');
                     $start = $start + self::LINE_LENGTH;
                     //add space if not last line
                     if ($start < $length) {
                         $block .= Constants::CRLF . ' ';
                     }
                 }
             } else {
                 $block = ' ' . $line;
             }
             $lines[] = $block . "\\n";
         }
     }
     $item = trim(implode(Constants::CRLF, $lines));
     $this->stream .= $item . Constants::CRLF;
     return $this;
 }
开发者ID:buggedcom,项目名称:ICS,代码行数:37,代码来源:CalendarStream.php

示例12: getList

 /**
  * грузим новости
  *
  * @param array $params
  * @param bool $user
  * @return array
  */
 public static function getList($params = [], $user = false)
 {
     if (empty($user)) {
         $user = Auth::instance()->get_user();
     }
     $db = Oracle::init();
     $agentIds = [$user['AGENT_ID']];
     if (!in_array($user['role'], array_keys(Access::$clientRoles))) {
         $agentIds[] = 0;
     }
     $sql = "select * from " . Oracle::$prefix . "V_WEB_NEWS where agent_id in (" . implode(',', $agentIds) . ")";
     $sql .= ' order by DATE_CREATE desc';
     if (!empty($params['pagination'])) {
         list($news, $more) = $db->pagination($sql, $params);
         foreach ($news as &$newsDetail) {
             $newsDetail['announce'] = strip_tags($newsDetail['CONTENT']);
             if (strlen($newsDetail['announce']) > 500) {
                 $newsDetail['announce'] = mb_strcut($newsDetail['announce'], 0, 500);
             }
         }
         return [$news, $more];
     }
     $news = $db->tree($sql, 'NEWS_ID', true);
     foreach ($news as &$newsDetail) {
         $newsDetail['announce'] = strip_tags($newsDetail['CONTENT']);
         if (strlen($newsDetail['announce']) > 500) {
             $newsDetail['announce'] = mb_strcut($newsDetail['announce'], 0, 500);
         }
     }
     return $news;
 }
开发者ID:paShaman,项目名称:Scala,代码行数:38,代码来源:News.php

示例13: sidebar_item_content_news

function sidebar_item_content_news($haswell = true)
{
    global $config, $db;
    $value = sidebar_item_top($haswell) . "            <h3>Latest News <span style='font-size:12px'><a href='news.php'>[more...]</a></span></h3>\n";
    $sql = "select * from news order by time_added desc limit 0," . $config["limits"]["news_on_index"];
    $none = true;
    foreach ($db->get_results($sql, ARRAY_A) as $row) {
        $none = false;
        $row['title'] = strip_tags($row['title']);
        if (strlen($row['title']) > $config["limits"]["news_on_index_title_len"]) {
            $row['title'] = mb_strcut($row['title'], 0, $config["limits"]["news_on_index_title_len"], 'UTF-8') . "<a name='" . $row['newsid'] . "' class='newslink' href='#'>[...]</a>";
        }
        $row['content'] = strip_tags($row['content']);
        if (strlen($row['content']) > $config["limits"]["news_on_index_content_len"]) {
            $row['content'] = mb_strcut($row['content'], 0, $config["limits"]["news_on_index_content_len"], 'UTF-8');
        }
        $row['content'] .= "<a name='" . $row['newsid'] . "' class='newslink' href='#'>[...]</a>";
        $value .= "            <h4>" . $row['title'] . "</h4>\n            <p>" . $row['content'] . "</p>\n";
    }
    if ($none) {
        $value .= "            No News.\n";
    }
    $value .= sidebar_item_bottom();
    return $value;
}
开发者ID:KinKir,项目名称:bnuoj-web-v3,代码行数:25,代码来源:sidebars.php

示例14: mysubstr

function mysubstr($s, $f, $l = 99999)
{
    if (XOOPS_USE_MULTIBYTES && function_exists("mb_strcut")) {
        return mb_strcut($s, $f, $l, _CHARSET);
    } else {
        return substr($s, $f, $l);
    }
}
开发者ID:nbuy,项目名称:xoops-modules-refpage,代码行数:8,代码来源:functions.php

示例15: bulkSMSRequest

 protected function bulkSMSRequest(MessageVO $message)
 {
     //GOIP message max length is 3000 bytes
     $cutmessage = mb_strcut($message->getMessage(), 0, 3000);
     $msg = "MSG " . $message->getId() . " " . strlen($cutmessage) . " " . $cutmessage . "\n";
     socket_sendto($this->socket, $msg, strlen($msg), 0, $this->address, $this->port);
     return $this->listenToReply($message, "BulkSMSConfirm", "PASSWORD");
 }
开发者ID:dudumiquim,项目名称:GOIP-PHP,代码行数:8,代码来源:goip.php


注:本文中的mb_strcut函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。