本文整理汇总了PHP中str_cut函数的典型用法代码示例。如果您正苦于以下问题:PHP str_cut函数的具体用法?PHP str_cut怎么用?PHP str_cut使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_cut函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: text2html
public static function text2html($string, $cutlen = false)
{
if (intval($cutlen) > 0) {
$string = str_cut($string, $cutlen);
}
return nl2br(str_replace(' ', ' ', self::new_htmlspecialchars($string)));
}
示例2: addart
function addart($catid, $title, $content)
{
$info = array();
$info['catid'] = 3;
$info['title'] = "api push";
$info['content'] = "absolutelu api push";
$db_config = pc_base::load_config('database');
pc_base::load_sys_class('mysql', '', 0);
pc_base::load_sys_class('param', '', 0);
$db = pc_base::load_model('content_model');
$categorys = getcache('category_content_1', 'commons');
$category = $categorys[3];
//var_dump($categorys);
$modelid = $category['modelid'];
//var_dump($modelid);
//die;
$db->set_model($modelid);
$setting = string2array($category['setting']);
$workflowid = $setting['workflowid'];
$info['status'] = 99;
$info['keywords'] = "";
$info['description'] = str_cut(str_replace(array("\r\n", "\t", '[page]', '[/page]', '“', '”', ' '), '', strip_tags($info['content'])), 200);
$info['username'] = "sumuya";
$info['inputtime'] = '';
echo "1";
if ($db->add_content($info)) {
return true;
}
return false;
}
示例3: post_query
function post_query($col)
{
include 'conn.php';
// Get the number of row of a table
$sql = "SELECT count(id) FROM blog";
$query = mysqli_query($conn, $sql);
$row = mysqli_fetch_row($query);
// Catch the session variable from another page
$n = $_SESSION['var'];
for ($i = 1; $i <= $row[0]; $i++) {
$sql = "SELECT * FROM blog where id = {$n} order by time asc";
// For query
$query = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($query);
if ($col == 'post_detail') {
str_cut($row['post_detail']);
break;
} elseif ($col == 'author') {
echo $row['author'];
break;
} elseif ($col == 'time') {
echo $row['time'];
break;
} elseif ($col == 'post_heading') {
echo $row['post_heading'];
break;
} elseif ($col == 'image') {
echo $row['image'];
break;
} elseif ($col == 'id') {
echo $row['id'];
break;
}
}
}
示例4: addart
function addart($catid, $title, $content)
{
$info = array();
$info['catid'] = $catid;
$info['title'] = $title;
$info['content'] = $content;
$db_config = pc_base::load_config('database');
pc_base::load_sys_class('mysql', '', 0);
pc_base::load_sys_class('param', '', 0);
$db = pc_base::load_model('content_model');
$category = $categorys[3];
$modelid = $category['modelid'];
$db->set_model($modelid);
$setting = string2array($category['setting']);
$workflowid = $setting['workflowid'];
$info['status'] = 99;
$info['keywords'] = get_keywords($info['title'], 3);
$info['description'] = str_cut(str_replace(array("\r\n", "\t", '[page]', '[/page]', '“', '”', ' '), '', strip_tags($info['content'])), 200);
$info['username'] = "admin";
$info['inputtime'] = '';
if ($db->add_content($info)) {
return true;
}
return false;
}
示例5: search
public function search()
{
$title = safe_replace($_GET['title']);
if (CHARSET == 'gbk') {
$title = iconv('utf-8', 'gbk', $title);
}
$where = '`status`=21';
if ($title) {
$where .= ' AND `title` LIKE \'%' . $title . '%\'';
}
$userupload = intval($_GET['userupload']);
if ($userupload) {
$where .= ' AND `userupload`=1';
}
$page = $_GET['page'];
$pagesize = 6;
$infos = $this->db->listinfo($where, 'videoid DESC', $page, $pagesize);
$number = $this->db->number;
$pages = $this->pages($number, $page, $pagesize, 4, 'get_videoes');
if (is_array($infos) && !empty($infos)) {
$html = '';
foreach ($infos as $info) {
$html .= '<li><div class="w9"><a href="javascript:void(0);" onclick="a_click(this);" title="' . $info['title'] . '" data-vid="' . $info['vid'] . '" ><span></span><img src="' . $info['picpath'] . '" width="90" height="51" /></a><p>' . str_cut($info['title'], 18) . '</p></div></li>';
}
}
$data['pages'] = $pages;
$data['html'] = $html;
if (CHARSET == 'gbk') {
$data = array_iconv($data, 'gbk', 'utf-8');
}
exit(json_encode($data));
}
示例6: get
function get($data, $isimport = 0)
{
$this->data = $data = trim_script($data);
$info = array();
foreach ($data as $field => $value) {
if (!isset($this->fields[$field]) && !check_in($field, 'paytype,paginationtype,maxcharperpage,id')) {
continue;
}
$name = $this->fields[$field]['name'];
$minlength = $this->fields[$field]['minlength'];
$maxlength = $this->fields[$field]['maxlength'];
$pattern = $this->fields[$field]['pattern'];
$errortips = $this->fields[$field]['errortips'];
if (empty($errortips)) {
$errortips = $name . ' 不符合要求';
}
$length = empty($value) ? 0 : (is_string($value) ? strlen($value) : count($value));
if ($minlength && $length < $minlength) {
if ($isimport) {
return false;
} else {
showmessage($name . ' 不得少于 ' . $minlength . ' 字符');
}
}
if ($maxlength && $length > $maxlength) {
if ($isimport) {
$value = str_cut($value, $maxlength, '');
} else {
showmessage($name . ' 不得多于 ' . $maxlength . ' 字符');
}
} elseif ($maxlength) {
$value = str_cut($value, $maxlength, '');
}
if ($pattern && $length && !preg_match($pattern, $value) && !$isimport) {
showmessage($errortips);
}
// 唯一性判断,和附加函数验证
/*$MODEL = getcache('model', 'commons');
$this->db->table_name = $this->fields[$field]['issystem'] ? $this->db_pre.$MODEL[$this->modelid]['tablename'] : $this->db_pre.$MODEL[$this->modelid]['tablename'].'_data';
if($this->fields[$field]['isunique'] && $this->db->get_one(array($field=>$value),$field) && ROUTE_A != 'edit') showmessage($name.L('the_value_must_not_repeat'));*/
$func = $this->fields[$field]['formtype'];
if (method_exists($this, $func)) {
$value = $this->{$func}($field, $value);
}
// var_dump($this->fields);
if ($this->fields[$field]['issystem']) {
$info['system'][$field] = $value;
} else {
$info['model'][$field] = $value;
}
}
//颜色选择为隐藏域 在这里进行取值
$info['system']['style'] = $_POST['style_color'] ? strip_tags($_POST['style_color']) : '';
if ($_POST['style_font_weight']) {
$info['system']['style'] = $info['system']['style'] . ';' . strip_tags($_POST['style_font_weight']);
}
return $info;
}
示例7: get
function get($data, $isimport = 0)
{
$this->data = $data = trim_script($data);
$info = array();
foreach ($data as $field => $value) {
//if(!isset($this->fields[$field]) || check_in($_roleid, $this->fields[$field]['unsetroleids']) || check_in($_groupid, $this->fields[$field]['unsetgroupids'])) continue;
$name = $this->fields[$field]['name'];
$minlength = $this->fields[$field]['minlength'];
$maxlength = $this->fields[$field]['maxlength'];
$pattern = $this->fields[$field]['pattern'];
$errortips = $this->fields[$field]['errortips'];
if (empty($errortips)) {
$errortips = $name . ' ' . L('not_meet_the_conditions');
}
$length = empty($value) ? 0 : strlen($value);
if ($minlength && $length < $minlength) {
if ($isimport) {
return false;
} else {
showmessage($name . ' ' . L('not_less_than') . ' ' . $minlength . L('characters'));
}
}
if ($maxlength && $length > $maxlength) {
if ($isimport) {
$value = str_cut($value, $maxlength, '');
} else {
showmessage($name . ' ' . L('not_more_than') . ' ' . $maxlength . L('characters'));
}
} elseif ($maxlength) {
$value = str_cut($value, $maxlength, '');
}
if ($pattern && $length && !preg_match($pattern, $value) && !$isimport) {
showmessage($errortips);
}
$MODEL = getcache('model', 'commons');
$this->db->table_name = $this->fields[$field]['issystem'] ? $this->db_pre . $MODEL[$this->modelid]['tablename'] : $this->db_pre . $MODEL[$this->modelid]['tablename'] . '_data';
if ($this->fields[$field]['isunique'] && $this->db->get_one(array($field => $value), $field) && ROUTE_A != 'edit') {
showmessage($name . L('the_value_must_not_repeat'));
}
$func = $this->fields[$field]['formtype'];
if (method_exists($this, $func)) {
$value = $this->{$func}($field, $value);
}
if ($this->fields[$field]['issystem']) {
$info['system'][$field] = $value;
} else {
$info['model'][$field] = $value;
}
//颜色选择为隐藏域 在这里进行取值
$info['system']['style'] = $_POST['style_color'] ? strip_tags($_POST['style_color']) : '';
if ($_POST['style_font_weight']) {
$info['system']['style'] = $info['system']['style'] . ';' . strip_tags($_POST['style_font_weight']);
}
}
return $info;
}
示例8: get
public function get($data, $isimport = 0)
{
$this->data = $data;
$info = array();
foreach ($data as $field => $value) {
$name = $this->fields[$field]['name'];
$minlength = $this->fields[$field]['minlength'];
$maxlength = $this->fields[$field]['maxlength'];
$pattern = $this->fields[$field]['pattern'];
$errortips = $this->fields[$field]['errortips'];
if (empty($errortips)) {
$errortips = $name . ' ' . L('not_meet_the_conditions');
}
$length = strlen($value);
if ($minlength && $length < $minlength) {
if ($isimport) {
return false;
} else {
showmessage($name . ' ' . L('not_less_than') . ' ' . $minlength . L('characters'));
}
}
if ($maxlength && $length > $maxlength) {
if ($isimport) {
$value = str_cut($value, $maxlength, '');
} else {
showmessage($name . ' ' . L('not_more_than') . ' ' . $maxlength . L('characters'));
}
} elseif ($maxlength) {
$value = str_cut($value, $maxlength, '');
}
if ($pattern && $length && !preg_match($pattern, $value) && !$isimport) {
showmessage($errortips);
}
$MODEL = S('common/model');
$this->db->table_name = $this->fields[$field]['issystem'] ? $this->db_pre . $MODEL[$this->modelid]['tablename'] : $this->db_pre . $MODEL[$this->modelid]['tablename'] . '_data';
if ($this->fields[$field]['isunique'] && $this->db->where(array($field => $value))->field($field)->find() && ACTION != 'edit') {
showmessage($name . L('the_value_must_not_repeat'));
}
$func = $this->fields[$field]['formtype'];
if (method_exists($this, $func)) {
$value = $this->{$func}($field, $value);
}
if ($this->fields[$field]['issystem']) {
$info['system'][$field] = $value;
} else {
$info['model'][$field] = $value;
}
// 颜色选择为隐藏域 在这里进行取值
$info['system']['style'] = isset($_POST['style_color']) ? strip_tags($_POST['style_color']) : '';
if (isset($_POST['style_font_weight'])) {
$info['system']['style'] = $info['system']['style'] . ';' . strip_tags($_POST['style_font_weight']);
}
}
return $info;
}
示例9: get
function get($data, $isimport = 0)
{
$this->data = $data = trim_script($data);
$info = array();
foreach ($this->fields as $field) {
//if(!isset($this->fields[$field]) || check_in($_roleid, $this->fields[$field]['unsetroleids']) || check_in($_groupid, $this->fields[$field]['unsetgroupids'])) continue;
$name = $field['name'];
$minlength = $field['minlength'];
$maxlength = $field['maxlength'];
$pattern = $field['pattern'];
$errortips = $field['errortips'];
$value = $data[$field['field']];
//if(empty($errortips)) $errortips = $name.' '.L('not_meet_the_conditions');
if (empty($errortips)) {
$errortips = "请输入正确的{$name}";
}
$length = is_array($value) ? empty($value) ? 0 : 1 : strlen($value);
if ($minlength && $length < $minlength) {
if ($isimport) {
return false;
} else {
showmessage($name . ' ' . L('not_less_than') . ' ' . $minlength . L('characters'));
}
}
if ($maxlength && $length > $maxlength) {
if ($isimport) {
$value = str_cut($value, $maxlength, '');
} else {
showmessage($name . ' ' . L('not_more_than') . ' ' . $maxlength . L('characters'));
}
} elseif ($maxlength) {
$value = str_cut($value, $maxlength, '');
}
if ($pattern && $length && !preg_match($pattern, $value) && !$isimport) {
showmessage($errortips);
}
$func = $field['formtype'];
if (method_exists($this, $func)) {
$value = $this->{$func}($field['field'], $value);
}
$info[$field['field']] = $value;
//颜色选择为隐藏域 在这里进行取值
if ($_POST['style_color']) {
$info['style'] = $_POST['style_color'];
}
if ($_POST['style_font_weight']) {
$info['style'] = $info['style'] . ';' . strip_tags($_POST['style_font_weight']);
}
}
return $info;
}
示例10: get
function get($data, $isimport = 0)
{
$this->data = $data = trim_script($data);
$info = array();
foreach ($data as $field => $value) {
if (!isset($this->fields[$field]) && !check_in($field, 'paytype,paginationtype,maxcharperpage,id')) {
continue;
}
$name = $this->fields[$field]['name'];
$minlength = $this->fields[$field]['minlength'];
$maxlength = $this->fields[$field]['maxlength'];
$pattern = $this->fields[$field]['pattern'];
$errortips = $this->fields[$field]['errortips'];
if (empty($errortips)) {
$errortips = $name . ' 不符合要求';
}
$length = empty($value) ? 0 : (is_string($value) ? strlen($value) : count($value));
if ($minlength && $length < $minlength) {
if ($isimport) {
return false;
} else {
showmessage($name . ' 不得少于 ' . $minlength . ' 字符');
}
}
if ($maxlength && $length > $maxlength) {
if ($isimport) {
$value = str_cut($value, $maxlength, '');
} else {
showmessage($name . ' 不得多于 ' . $maxlength . ' 字符');
}
} elseif ($maxlength) {
$value = str_cut($value, $maxlength, '');
}
if ($pattern && $length && !preg_match($pattern, $value) && !$isimport) {
showmessage($errortips);
}
// 附加函数验证
$func = $this->fields[$field]['formtype'];
if (method_exists($this, $func)) {
$value = $this->{$func}($field, $value);
}
$info['system'][$field] = $value;
}
//颜色选择为隐藏域 在这里进行取值
$info['system']['style'] = $_POST['style_color'] ? strip_tags($_POST['style_color']) : '';
if ($_POST['style_font_weight']) {
$info['system']['style'] = $info['system']['style'] . ';' . strip_tags($_POST['style_font_weight']);
}
return $info;
}
示例11: get
function get($data)
{
$this->data = $data = trim_script($data);
$model_cache = getcache('member_model', 'commons');
$this->db->table_name = $this->db_pre . $model_cache[$this->modelid]['tablename'];
$info = array();
$debar_filed = array('catid', 'title', 'style', 'thumb', 'status', 'islink', 'description');
if (is_array($data)) {
foreach ($data as $field => $value) {
if ($data['islink'] == 1 && !in_array($field, $debar_filed)) {
continue;
}
$field = safe_replace($field);
$name = $this->fields[$field]['name'];
$minlength = $this->fields[$field]['minlength'];
$maxlength = $this->fields[$field]['maxlength'];
$pattern = $this->fields[$field]['pattern'];
$errortips = $this->fields[$field]['errortips'];
if (empty($errortips)) {
$errortips = "{$name} 不符合要求!";
}
$length = empty($value) ? 0 : strlen($value);
if ($minlength && $length < $minlength && !$isimport) {
showmessage("{$name} 不得少于 {$minlength} 个字符!");
}
if (!array_key_exists($field, $this->fields)) {
showmessage('模型中不存在' . $field . '字段');
}
if ($maxlength && $length > $maxlength && !$isimport) {
showmessage("{$name} 不得超过 {$maxlength} 个字符!");
} else {
str_cut($value, $maxlength);
}
if ($pattern && $length && !preg_match($pattern, $value) && !$isimport) {
showmessage($errortips);
}
if ($this->fields[$field]['isunique'] && $this->db->get_one(array($field => $value), $field) && ROUTE_A != 'edit') {
showmessage("{$name} 的值不得重复!");
}
$func = $this->fields[$field]['formtype'];
if (method_exists($this, $func)) {
$value = $this->{$func}($field, $value);
}
$info[$field] = $value;
}
}
return $info;
}
示例12: index
public function index()
{
$model = M('Article');
$data['status'] = 1;
$count = $model->where($data)->count();
$page_size = $_REQUEST['page_size'] ? $_REQUEST['page_size'] : C('default_page_size');
$page_count = ceil($count / $page_size);
$pageno = 1;
$offset = ($pageno - 1) * $page_size;
$voList = $model->field('id,title,content,litpic,create_time')->where($data)->limit($offset . ',' . $page_size)->select();
foreach ($voList as $key => $val) {
$voList[$key]['content'] = str_cut(htmlspecialchars_decode($val['content']), 45);
}
$list['count'] = $count;
$list['page_count'] = $page_count;
$list['data'] = $voList;
echo json_encode($list);
exit;
}
示例13: joy
function joy($id)
{
$session_id = "joy_src" . $id;
$src = $_SESSION[$session_id];
if (empty($src)) {
//注意msxv5v2可能是个验证值,以后可能会变更,将导致无法获取
$url = "http://msx.app.joy.cn/service.php?action=msxv5v2&playertype=joyplayer&videoid=" . $id;
$str = get_data($url);
if ($str) {
$s1 = str_cut($str, "<HostPath", "/HostPath>");
$s11 = str_cut($s1, ">", "<");
$s2 = str_cut($str, "<Url", "</Url>");
$s21 = str_cut($s2, "<![CDATA[", "]]>");
$src = $s11 . $s21;
//echo $src;
$_SESSION[$session_id] = $src;
}
}
return $src;
}
示例14: autoHookHead
function autoHookHead(&$style, $isReply)
{
global $PIO, $FileIO;
if ($isReply) {
$p = $PIO->fetchPosts($isReply);
$sub = $p[0]['sub'];
$com = htmlentities(str_cut($p[0]['com'], 100), ENT_QUOTES, 'UTF-8');
$thumb = '';
if ($p[0]['ext'] != '') {
$thumb = $FileIO->resolveThumbName($p[0]['tim']);
// 檢查是否有預覽圖可以顯示
$thumb = $thumb ? $FileIO->getImageURL($thumb) : '';
}
$style .= <<<_HERE_
<meta property="og:image" content="{$thumb}" />
<meta property="og:title" content="{$sub} - {$this->site}" />
<meta property="og:description" content="{$com}" />
_HERE_;
}
}
示例15: new_age
function new_age()
{
$msg = M('Message');
$limit = $_POST['limit'];
$current = I('get.page', 1);
$art = ($current - 1) * $limit;
$url = get_url();
//获取当前页面的URL地址
$fir = strpos($url, 'page');
if ($fir) {
$purl = mb_substr($url, 0, $fir - 1);
} else {
$purl = $url;
}
$count = $msg->count();
$show = list_page($current, $limit, $count, $purl);
$msg = $msg->order('msg_addtime DESC')->limit($art, $limit)->select();
foreach ($msg as $key => $val) {
$msg[$key]['msg_ctitle'] = str_cut($val['msg_content'], 0, 21);
}
$data = array('msg' => $msg, 'show' => $show);
echo json_encode($data);
}