本文整理汇总了PHP中mb_strimwidth函数的典型用法代码示例。如果您正苦于以下问题:PHP mb_strimwidth函数的具体用法?PHP mb_strimwidth怎么用?PHP mb_strimwidth使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mb_strimwidth函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
/**
* query 對 db 下 SQL query
*
* @param mixed $sql
* @access protected
* @return Mysqli result
*/
public function query($sql, $table = null)
{
$short_sql = mb_strimwidth($sql, 0, 512, "...len=" . strlen($sql));
if (Pix_Table::$_log_groups[Pix_Table::LOG_QUERY]) {
Pix_Table::debug(sprintf("[%s]\t%40s", $this->_link->host_info, $short_sql));
}
// TODO 需要 log SQL Query 功能
if ($comment = Pix_Table::getQueryComment()) {
$sql = trim($sql, '; ') . ' #' . $comment;
}
$starttime = microtime(true);
$res = $this->_link->query($sql);
if ($t = Pix_Table::getLongQueryTime() and ($delta = microtime(true) - $starttime) > $t) {
Pix_Table::debug(sprintf("[%s]\t%s\t%40s", $this->_link->host_info, $delta, $sql));
}
if ($res === false) {
if ($errno = $this->_link->errno) {
switch ($errno) {
case 1062:
throw new Pix_Table_DuplicateException($this->_link->error, $errno);
case 1406:
throw new Pix_Table_DataTooLongException($this->_link->error, $errno);
default:
throw new Exception("SQL Error: {$this->_link->error} SQL: {$sql}");
}
}
}
return $res;
}
示例2: widget
function widget($args, $instance)
{
extract($args);
$user_id = $instance['user_id'];
if (empty($user_id)) {
if (is_author()) {
$user_id = get_queried_object_id();
} else {
return;
}
}
$title = apply_filters('widget_title', $title, $instance, $this->id_base);
$title = sprintf($instance['title'], '<span class="display-name">' . get_the_author_meta('display_name', $user_id) . '</span>');
$bio = get_the_author_meta('description', $user_id);
if ($instance['strip_tags']) {
$bio = strip_tags($bio);
}
if (function_exists('mb_strimwidth') && ($bio_length = $instance['bio_length'])) {
$bio = mb_strimwidth($bio, 0, $bio_length);
}
echo $before_widget;
if (!empty($title)) {
echo $before_title . $title . $after_title;
}
echo '<div class="bio">' . wpautop($bio) . '</div>';
echo $after_widget;
}
示例3: index
public function index()
{
// 首页的标题,关键词,描述
$siteInfo = M('enewspublic')->field('sitename, sitekey, siteintro')->find();
$this->assign('siteInfo', $siteInfo);
// 图片资讯 推1
$picArticles = $this->getArticles('', 5, 1, 1);
$this->assign('picArticles', $picArticles);
// 热点推荐 推2
$recommArticles = $this->getArticles('', 5, 0, 2);
$recommContent = $this->formatArticleContent($recommArticles[0]['newstext']);
$recommArticles[0]['newstext'] = mb_strimwidth(strip_tags($recommContent), 0, 150, '...', 'utf-8');
$this->assign('recommArticles', $recommArticles);
// 普通资讯 推3
$normalArticles = $this->getArticles('', 1, 0, 3);
$normalContent = $this->formatArticleContent($normalArticles['newstext']);
$normalArticles['newstext'] = mb_strimwidth(strip_tags($normalContent), 0, 400, '...', 'utf-8');
$normalArticles['wordcount'] = mb_strlen(strip_tags($normalContent));
$this->assign('normalArticles', $normalArticles);
// 滚动图片 推4
$rollPics = $this->getArticles('', 16, 1, 4);
$this->assign('rollPics', $rollPics);
// 动作分类 科幻魔幻 情景喜剧 ...
$classArticles = $this->classArticles();
$this->assign('classArticles', $classArticles);
// 文章归档
$archives = $this->archives();
$this->assign('archives', $archives);
// 友情链接
$friendlyLink = $this->friendlyLink();
$this->assign('friendlyLink', $friendlyLink);
$this->display();
}
示例4: query
public function query($sql)
{
$short_sql = mb_strimwidth($sql, 0, 512, "...len=" . strlen($sql));
if (Pix_Table::$_log_groups[Pix_Table::LOG_QUERY]) {
Pix_Table::debug(sprintf("[%s]\t%40s", $this->_path . $this->_name, $short_sql));
}
$starttime = microtime(true);
$statement = $this->_pdo->prepare($sql);
if (!$statement) {
if ($errno = $this->_pdo->errorCode()) {
$errorInfo = $this->_pdo->errorInfo();
}
if ($errorInfo[2] == 'PRIMARY KEY must be unique' or preg_match('/duplicate key value violates unique constraint/', $errorInfo[2])) {
throw new Pix_Table_DuplicateException($errorInfo[2]);
}
throw new Exception("SQL Error: ({$errorInfo[0]}:{$errorInfo[1]}) {$errorInfo[2]} (SQL: {$short_sql})");
}
$res = $statement->execute();
if ($t = Pix_Table::getLongQueryTime() and ($delta = microtime(true) - $starttime) > $t) {
Pix_Table::debug(sprintf("[%s]\t%s\t%40s", $this->_pdo->getAttribute(PDO::ATTR_SERVER_INFO), $delta, $short_sql));
}
if ($res === false) {
if ($errno = $statement->errorCode()) {
$errorInfo = $statement->errorInfo();
}
if ($errorInfo[2] == 'PRIMARY KEY must be unique' or preg_match('/duplicate key value violates unique constraint/', $errorInfo[2])) {
throw new Pix_Table_DuplicateException($errorInfo[2]);
}
throw new Exception("SQL Error: ({$errorInfo[0]}:{$errorInfo[1]}) {$errorInfo[2]} (SQL: {$short_sql})");
}
return new Pix_Table_Db_Adapter_PDO_Result($statement);
}
示例5: substr_content
function substr_content($content)
{
if (!is_singular()) {
$content = mb_strimwidth(strip_tags($content), 0, 310);
}
return $content;
}
示例6: execute
/**
* Execute the command.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return void
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$client = new Client();
$modname = $input->getArgument('modname');
$modversion = $input->getArgument('modversion');
$config = solder_config();
$response = $client->get($config->api);
$server = $response->json();
$response = $client->get($config->api . '/mod/' . $modname . '/' . $modversion);
$json = $response->json();
if (isset($json['error'])) {
throw new \Exception($json['error']);
}
$rows = array();
foreach ($json as $key => $value) {
if ($key == 'versions') {
$rows[] = array("<info>{$key}</info>", implode($value, "\n"));
} else {
$rows[] = array("<info>{$key}</info>", mb_strimwidth($value, 0, 80, "..."));
}
}
$output->writeln('<comment>Server:</comment>');
$output->writeln(" <info>{$server['api']}</info> version {$server['version']}");
$output->writeln(" {$api}");
$output->writeln('');
$output->writeln("<comment>Mod:</comment>");
$table = new Table($output);
$table->setRows($rows)->setStyle('compact')->render();
}
示例7: smarty_modifier_wordwrap_i18n
/**
* smarty modifier:文字列のwordwrap処理
*
* sample:
* <code>
* {"あいうaえaおaかきaaaくけこ"|wordwrap_i18n:8}
* </code>
* <code>
* あいうa
* えaおaか
* きaaaく
* けこ
* </code>
*
* @param string $string wordwrapする文字列
* @param string $break 改行文字
* @param int $width wordwrap幅(半角$width文字でwordwrapする)
* @param int $indent インデント幅(半角$indent文字)
* 数値を指定するが、はじめの行はインデントされない
* @return string wordwrap処理された文字列
*/
function smarty_modifier_wordwrap_i18n($string, $width, $break = "\n", $indent = 0)
{
$ctl = Ethna_Controller::getInstance();
$client_enc = $ctl->getClientEncoding();
// いわゆる半角を単位にしてwrapする位置を測るため、いったん
// EUC_JP に変換する
$euc_string = mb_convert_encoding($string, 'EUC_JP', $client_enc);
$r = "";
$i = "{$break}" . str_repeat(" ", $indent);
$tmp = $euc_string;
do {
$n = strpos($tmp, $break);
if ($n !== false && $n < $width) {
$s = substr($tmp, 0, $n);
$r .= $s . $i;
$tmp = substr($tmp, strlen($s) + strlen($break));
continue;
}
$s = mb_strimwidth($tmp, 0, $width, "", 'EUC_JP');
$tmp = substr($tmp, strlen($s));
$r .= $s . (strlen($tmp) > 0 ? $i : '');
} while (strlen($tmp) > 0);
// 最後に、クライアントエンコーディングに変換
$r = mb_convert_encoding($r, $client_enc, 'EUC_JP');
return $r;
}
示例8: limit
/**
* Limit the number of characters in a string.
*
* @param string $value
* @param int $limit
* @param string $end
*
* @return string
*/
public static function limit(string $value, int $limit = 100, string $end = '...') : string
{
if (mb_strwidth($value, 'UTF-8') <= $limit) {
return $value;
}
return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
}
示例9: endElement
function endElement($parser, $tagName)
{
if ($tagName == "ITEM") {
//if ($this->status) print "[$this->status] ";
$title = trim($this->title);
if (!empty($this->title_width) && function_exists('mb_strimwidth')) {
$title = mb_strimwidth($title, 0, $this->title_width, '...', $this->charset);
}
$title = sprintf("<a href='%s' title='%s' target='_content'>%s</a>", trim($this->link), _html_escape($this->title), _html_escape($title));
#printf("<p>%s</p>",
# _html_escape(trim($this->description)));
if ($this->date) {
$date = trim($this->date);
$date[10] = " ";
# 2003-07-11T12:08:33+09:00
# http://www.w3.org/TR/NOTE-datetime
$zone = str_replace(":", "", substr($date, 19));
$time = strtotime(substr($date, 0, 19) . $zone);
$date = date($this->date_fmt, $time);
}
echo '<li><span data-timestamp="' . $time . '" class="date">', $date, '</span> ', $title, '</li>', "\n";
$this->title = "";
$this->description = "";
$this->link = "";
$this->date = "";
$this->status = "";
$this->insideitem = false;
}
}
示例10: mini_content
public function mini_content($length = 100)
{
if (!isset($this->content)) {
return '';
}
return $length ? mb_strimwidth(remove_ckedit_tag($this->content), 0, $length, '…', 'UTF-8') : remove_ckedit_tag($this->content);
}
示例11: msubstr
/**
* 字符串截取,支持中文和其他编码
* @static
* @access public
* @param string $str 需要转换的字符串
* @param string $start 开始位置
* @param string $length 截取长度
* @param string $charset 编码格式
* @param string $suffix 截断显示字符
* @return string
*/
function msubstr($str, $start = 0, $length, $charset = "utf-8", $suffix = false)
{
if (function_exists("mb_strimwidth")) {
$slice = mb_strimwidth($str, $start, $length, '', $charset);
// mb_strimwidth 截取字符串 中文算2个字节,英文算1个
} elseif (function_exists('mb_substr')) {
$slice = mb_substr($str, $start, $length, $charset);
} elseif (function_exists("iconv_substr")) {
$slice = iconv_substr($str, $start, $length, $charset);
} else {
$re['utf-8'] = "/[-]|[�-�][�-�]|[�-�][�-�]{2}|[�-�][�-�]{3}/";
$re['gb2312'] = "/[-]|[�-�][�-�]/";
$re['gbk'] = "/[-]|[�-�][@-�]/";
$re['big5'] = "/[-]|[�-�]([@-~]|�-�])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("", array_slice($match[0], $start, $length));
}
if ($suffix) {
return mb_strwidth($slice, $charset) > $length ? $slice : $slice . '...';
// mb_strwidth 计算字符串长度 中文算2个字节,英文算1个
} else {
return $slice;
}
// return $suffix ? $slice.'...' : $slice;
}
示例12: trimTitles
private function trimTitles($data)
{
foreach ($data as &$entry) {
$entry['label'] = utf8_encode(mb_strimwidth(@$entry['label'], 0, 25, "..."));
}
return $data;
}
示例13: mini_href
public function mini_href($length = 80)
{
if (!isset($this->href)) {
return '';
}
return $length ? mb_strimwidth(remove_ckedit_tag($this->href), 0, $length, '…', 'UTF-8') : remove_ckedit_tag($this->href);
}
示例14: getDatatable
/**
* getDatatable
* Gets the datatable for the index page
*
* @return mixed
* @author Vincent Sposato <vincent.sposato@gmail.com>
* @version v1.0
*/
public function getDatatable()
{
$assetMaintenances = AssetMaintenance::orderBy('created_at', 'DESC')->get();
$actions = new \Chumper\Datatable\Columns\FunctionColumn('actions', function ($assetMaintenances) {
return '<a href="' . route('update/asset_maintenance', $assetMaintenances->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('delete/asset_maintenance', $assetMaintenances->id) . '" data-content="' . Lang::get('admin/asset_maintenances/message.delete.confirm') . '" data-title="' . Lang::get('general.delete') . ' ' . htmlspecialchars($assetMaintenances->title) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
});
return Datatable::collection($assetMaintenances)->addColumn('asset', function ($assetMaintenances) {
return link_to('/hardware/' . $assetMaintenances->asset_id . '/view', mb_strimwidth($assetMaintenances->asset->name, 0, 50, "..."));
})->addColumn('supplier', function ($assetMaintenances) {
return link_to('/admin/settings/suppliers/' . $assetMaintenances->supplier_id . '/view', mb_strimwidth($assetMaintenances->supplier->name, 0, 50, "..."));
})->addColumn('asset_maintenance_type', function ($assetMaintenances) {
return $assetMaintenances->asset_maintenance_type;
})->addColumn('title', function ($assetMaintenances) {
return link_to('/admin/asset_maintenances/' . $assetMaintenances->id . '/view', mb_strimwidth($assetMaintenances->title, 0, 50, "..."));
})->addColumn('start_date', function ($assetMaintenances) {
return $assetMaintenances->start_date;
})->addColumn('completion_date', function ($assetMaintenances) {
return $assetMaintenances->completion_date;
})->addColumn('asset_maintenance_time', function ($assetMaintenances) {
if (is_null($assetMaintenances->asset_maintenance_time)) {
$assetMaintenances->asset_maintenance_time = Carbon::now()->diffInDays(Carbon::parse($assetMaintenances->start_date));
}
return intval($assetMaintenances->asset_maintenance_time);
})->addColumn('cost', function ($assetMaintenances) {
return sprintf(Lang::get('general.currency') . '%01.2f', $assetMaintenances->cost);
})->addColumn($actions)->searchColumns('asset', 'supplier', 'asset_maintenance_type', 'title', 'start_date', 'completion_date', 'asset_maintenance_time', 'cost', 'actions')->orderColumns('asset', 'supplier', 'asset_maintenance_type', 'title', 'start_date', 'completion_date', 'asset_maintenance_time', 'cost', 'actions')->make();
}
示例15: str_limit
function str_limit($value, $limit = 100, $end = '...')
{
if (mb_strwidth($value, 'UTF-8') <= $limit) {
return $value;
}
return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end;
}