本文整理汇总了PHP中iconv_substr函数的典型用法代码示例。如果您正苦于以下问题:PHP iconv_substr函数的具体用法?PHP iconv_substr怎么用?PHP iconv_substr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了iconv_substr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: msubstr
/**
* 截取字符串
* @param $st
* 要截取的字符串
* @param $start
* 开始位置
* @param $length
* 截取的长度
* @param $charset
* 字符编码
* @param $suffix
* 是否显示 "... "
* @return String
*
*/
public static function msubstr($str, $start = 0, $length, $charset = 'UTF8', $suffix = true)
{
//字符占位宽
$width = 0;
//处理后的字符串
$cut_str = '';
//debug
if ($charset == 'utf-8') {
$charset = 'UTF8';
}
if (function_exists('mb_strlen')) {
$width = (strlen($str) + mb_strlen($str, $charset)) / 2;
} else {
$width = strlen($str) / 2;
}
if ($width > $length) {
if (function_exists('mb_substr')) {
$cut_str = mb_substr($str, $start, $length, $charset);
} elseif (function_exists('iconv_substr')) {
$cut_str = iconv_substr($str, $start, $length, $charset);
}
} else {
$cut_str = $str;
}
if ($suffix) {
$cut_str = $cut_str . '...';
}
return $cut_str;
}
示例2: posts_list
public function posts_list()
{
$this->display('Public:head');
$tag = I('get.tag');
$c_tag = $this->tag_exists($tag);
$db_name = CONTROLLER_NAME . '_' . $tag;
$m = M($db_name);
$count = $m->where(array('isT' => 1))->count();
//分页
$Page = new \Think\Page($count, 10);
$Page->setConfig('theme', '当前第%NOW_PAGE%页 共%TOTAL_PAGE%页 %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% <b>%HEADER%</b> ');
$pager = $Page->show();
$posts = $m->where(array('isT' => 1))->order('last_post_time desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
foreach ($posts as $k => $v) {
$posts[$k]['content'] = iconv_substr($v['content'], 0, 300, 'utf-8');
}
//dump($posts);
//dump($pager);
// exit;
$this->assign('tag', $tag);
$this->assign('c_tag', $c_tag);
$this->assign('posts', $posts);
$this->assign('pager', $pager);
$this->display();
$this->display('Public:foot');
}
示例3: _saveVisitorInfo
/**
* Saving visitor information
*
* @param Mage_Log_Model_Visitor $visitor
* @return Mage_Log_Model_Mysql4_Visitor
*/
protected function _saveVisitorInfo($visitor)
{
$write = $this->_getWriteAdapter();
$data = array('visitor_id' => $visitor->getId(), 'http_referer' => iconv_substr($visitor->getHttpReferer(), 0, 250), 'http_user_agent' => $visitor->getHttpUserAgent(), 'http_accept_charset' => $visitor->getHttpAcceptCharset(), 'http_accept_language' => $visitor->getHttpAcceptLanguage(), 'server_addr' => $visitor->getServerAddr(), 'remote_addr' => $visitor->getRemoteAddr());
$write->insert($this->getTable('log/visitor_info'), $data);
return $this;
}
示例4: adjDBValue
function adjDBValue($value, $len = -1)
{
if ($value === null) {
return null;
}
if (is_array($value)) {
foreach ($value as $key => $val) {
$value[$key] = adjDBValue($val, $len);
}
} else {
$value = trim($value);
// NON-Multibyte here!
if (strlen($value) == 0) {
// NON-Multibyte here!
return null;
}
if ($len >= 0) {
// Multibyte here!
if (defined('R3_APP_CHARSET_DB')) {
// PHP-BUG (iconv_substr($value, 0, 1, "UFT-8"); faild!)
if (iconv_strlen($value, R3_APP_CHARSET_DB) > 1) {
$value = iconv_substr($value, 0, $len, R3_APP_CHARSET_DB);
}
} else {
$value = substr($value, 0, $len);
}
}
}
return $value;
}
示例5: sanitize
/**
* Filter: removes unnecessary whitespace and shortens value to control's max length.
* @return string
*/
public function sanitize($value)
{
if ($this->control->maxlength && iconv_strlen($value, 'UTF-8') > $this->control->maxlength) {
$value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
}
return String::trim(strtr($value, "\r\n", ' '));
}
示例6: msubstr
function msubstr($str, $start = 0, $length, $charset = "utf-8", $suffix = true)
{
if (function_exists("mb_substr")) {
if ($suffix) {
return mb_substr($str, $start, $length, $charset) . "...";
} else {
return mb_substr($str, $start, $length, $charset);
}
} elseif (function_exists('iconv_substr')) {
if ($suffix) {
return iconv_substr($str, $start, $length, $charset) . "...";
} else {
return iconv_substr($str, $start, $length, $charset);
}
}
$re['utf-8'] = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef]\r\n [x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";
$re['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/";
$re['gbk'] = "/[x01-x7f]|[x81-xfe][x40-xfe]/";
$re['big5'] = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/";
preg_match_all($re[$charset], $str, $match);
$slice = join("", array_slice($match[0], $start, $length));
if ($suffix) {
return $slice . "…";
}
return $slice;
}
示例7: sanitize
/**
* Filter: removes unnecessary whitespace and shortens value to control's max length.
* @return string
*/
public function sanitize($value)
{
if ($this->control->maxlength && Nette\Utils\Strings::length($value) > $this->control->maxlength) {
$value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
}
return Nette\Utils\Strings::trim(strtr($value, "\r\n", ' '));
}
示例8: truncate
public function truncate($string, $length = 50, $chars = true, $postfix = '...')
{
$truncated = trim($string);
if (!$string) {
return $truncated;
}
$length = (int) $length;
if ($chars) {
$fullLength = iconv_strlen($truncated, 'UTF-8');
if ($fullLength > $length) {
$truncated = trim(iconv_substr($truncated, 0, $length, 'UTF-8')) . $postfix;
}
// words
} else {
$truncated = str_replace(' ', ' ', $truncated);
$words = explode(' ', $truncated);
$truncated = '';
$count = count($words);
for ($i = 0; $i < $count; $i++) {
$truncated .= $words[$i] . ' ';
if ($length == $i) {
$truncated .= $postfix;
break;
}
}
}
return $truncated;
}
示例9: updateAction
public function updateAction()
{
//处理接收参数
$id = intval($this->_getParam('id'));
$pid = intval($this->_getParam('pid'));
$catName = iconv_substr($this->_getParam('catname'), 0, 100, 'utf-8');
$description = iconv_substr($this->_getParam('description'), 0, 500, 'utf-8');
$display = intval($this->_getParam('display'));
$order = intval($this->_getParam('order'));
//是否显示赋值
$display !== 0 && ($display = 1);
if (empty($catName)) {
Zshop_Message::show($this, '带*号内容必须输入', 'back', 2);
} else {
$catalog = array('pid' => $pid, 'catname' => $catName, 'display' => $display, 'description' => $description, 'order' => $order);
$isUpdated = $this->goodsCatalogModel->update($catalog, $id);
if ($isUpdated) {
$message = '修改成功';
$url = 'admin/goodscatalog/index';
} else {
$message = '修改失败';
$url = 'back';
}
Zshop_Message::show($this, $message, $url, 2);
}
}
示例10: sub_str
/**
* 截取UTF-8下字符串的函数
*
* @param string $str
* @param int $length
* @param bool $append
*
* @return string
*/
protected static function sub_str($str, $length = 0, $append = true)
{
$str = trim($str);
$strlength = strlen($str);
if ($length == 0 || $length >= $strlength) {
return false;
} else {
if ($length < 0) {
$length = $strlength + $length;
if ($length < 0) {
$length = $strlength;
}
}
}
if (function_exists('mb_substr')) {
$newstr = mb_substr($str, 0, $length, 'UTF-8');
} else {
if (function_exists('iconv_substr')) {
$newstr = iconv_substr($str, 0, $length, 'UTF-8');
} else {
$newstr = substr($str, 0, $length);
}
}
if ($append && $str != $newstr) {
$newstr .= '...';
}
return $newstr;
}
示例11: cstr
public function cstr($text, $start = 0, $limit = 12)
{
if (function_exists('mb_substr')) {
$more = mb_strlen($text) > $limit ? TRUE : FALSE;
$text = mb_substr($text, 0, $limit, 'UTF-8');
return array($text, $more);
} elseif (function_exists('iconv_substr')) {
$more = iconv_strlen($text) > $limit ? TRUE : FALSE;
$text = iconv_substr($text, 0, $limit, 'UTF-8');
return array($text, $more);
} else {
preg_match_all("/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf]\r\n \t\t[x80-xbf]|[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]\r\n \t\t|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/", $text, $ar);
if (func_num_args() >= 3) {
if (count($ar[0]) > $limit) {
$more = TRUE;
$text = join("", array_slice($ar[0], 0, $limit));
}
$more = TRUE;
$text = join("", array_slice($ar[0], 0, $limit));
} else {
$more = FALSE;
$text = join("", array_slice($ar[0], 0));
}
return array($text, $more);
}
}
示例12: Cut
/**
* cut string
*
* @param string $value
* @param int $len
* @param string $encode
* @return string
*/
public static function Cut($value, $len, $encode = "UTF-8")
{
if (empty($value)) {
return $value;
}
return iconv_substr($value, 0, $len, $encode);
}
示例13: msubstr
function msubstr($str, $start = 0, $length, $charset = "utf-8", $suffix = true)
{
if (function_exists("mb_substr")) {
if ($suffix && strlen($str) > $length) {
return mb_substr($str, $start, $length, $charset) . "...";
} else {
return mb_substr($str, $start, $length, $charset);
}
} elseif (function_exists('iconv_substr')) {
if ($suffix && strlen($str) > $length) {
return iconv_substr($str, $start, $length, $charset) . "...";
} else {
return iconv_substr($str, $start, $length, $charset);
}
}
$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 $slice . "…";
}
return $slice;
}
示例14: 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 = '...')
{
$total = 0;
if (function_exists("mb_substr")) {
$total = mb_strlen($str, $charset);
if ($total <= $length) {
return $str;
}
$slice = mb_substr($str, $start, $length, $charset);
} elseif (function_exists('iconv_substr')) {
$total = iconv_strlen($str, $charset);
if ($total <= $length) {
return $str;
}
$slice = iconv_substr($str, $start, $length, $charset);
if (false === $slice) {
$slice = '';
}
} else {
$re['utf-8'] = "/[-]|[�-�][�-�]|[�-�][�-�]{2}|[�-�][�-�]{3}/";
$re['gb2312'] = "/[-]|[�-�][�-�]/";
$re['gbk'] = "/[-]|[�-�][@-�]/";
$re['big5'] = "/[-]|[�-�]([@-~]|�-�])/";
preg_match_all($re[$charset], $str, $match);
$total = count($match[0]);
if ($total <= $length) {
return $str;
}
$slice = join("", array_slice($match[0], $start, $length));
}
return $suffix ? $slice . $suffix : $slice;
}
示例15: 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;
}