• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP str_limit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: substr_text_only

function substr_text_only($string, $limit, $end = '...')
{
    $with_html_count = strlen($string);
    $without_html_count = strlen(strip_tags($string));
    $html_tags_length = $with_html_count - $without_html_count;
    return str_limit($string, $limit + $html_tags_length, $end);
}
开发者ID:Erbenos,项目名称:laravel-blog,代码行数:7,代码来源:helpers.php


示例2: grid

 /**
  * Processes displaying the data to the grid
  *
  * @return DataGrid
  * @throws \Stevebauman\LogReader\Exceptions\UnableToRetrieveLogFilesException
  */
 public function grid()
 {
     $columns = ['id', 'level', 'date', 'header'];
     $settings = ['sort' => 'date', 'direction' => 'desc', 'pdf_view' => 'pdf'];
     $transformer = function ($element) {
         $element['level'] = $this->levelToLabel($element['level']);
         $element['show_url'] = route('admin.logs.show', array($element['id']));
         $element['header'] = str_limit($element['header']);
         return $element;
     };
     $reader = $this->reader;
     $filters = request()->input('filters');
     if (is_array($filters)) {
         /*
          * If an include_read filter is toggled, make sure
          * we toggle it on the log reader
          */
         foreach ($filters as $filter) {
             if (array_key_exists('include_read', $filter)) {
                 $reader->includeRead();
             }
         }
     }
     return datagrid($reader->get(), $columns, $settings, $transformer);
 }
开发者ID:stevebauman,项目名称:platform-logs,代码行数:31,代码来源:LogController.php


示例3: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //handel the request
     $validator = Validator::make($request->all(), ['title' => 'required|unique:posts|max:67', 'image' => 'required|image|mimes:jpeg,png|max:5000']);
     if ($validator->fails()) {
         return redirect('seodashboard/posts/create')->withErrors($validator)->withInput();
     }
     $post = new Post();
     $post->title = $request->input('title');
     $post->content = $request->input('content');
     $post->published = $request->input('status');
     $post->excrypt = str_limit($request->input('excrypt'), 155);
     $tags = $request->input('tags');
     $categories = $request->input('categories');
     $tags = $this->ConvertTagsToList($tags);
     //save image path in database
     if ($request->hasFile('image')) {
         $destinationPath = 'images';
         $file = $request->file('image');
         $fileName = $file->getClientOriginalName();
         $file->move($destinationPath, $fileName);
         $post->image = $fileName;
     }
     $post->save();
     $post->tags()->attach($tags);
     $post->categories()->attach($categories);
     return redirect('seodashboard/posts');
 }
开发者ID:AhmedMedo,项目名称:Seo,代码行数:34,代码来源:PostController.php


示例4: updateDescription

 public function updateDescription()
 {
     if ($this->content == null) {
         return;
     }
     $this->description = str_limit(strip_tags($this->content), 200);
 }
开发者ID:sandywalker,项目名称:xiehouxing,代码行数:7,代码来源:Note.php


示例5: getIncidents

    public function getIncidents()
    {
        $incidents = ITP::select(['ID', 'Title', 'ReportingOrg', 'ImpactDescription', 'BriefDescription', 'IncidentLevel', 'Date', 'Section', 'IncidentOwner', 'Engineer', 'IncidentStatus']);
        $datatables = Datatables::of($incidents)->editColumn('BriefDescription', function ($incident) {
            return '
					<div class="text-semibold"><a href="./incident/' . $incident->ID . '/edit">' . str_limit($incident->Title, 40) . '</a></div>
                    <div class="text-muted">' . str_limit($incident->BriefDescription, 80) . '</div>
				';
        })->removeColumn('Title');
        if ($months = $datatables->request->get('months')) {
            $datatables->where(function ($query) use($months) {
                foreach ($months as $month) {
                    $query->orWhereRaw('MONTH(Date) = ' . $month);
                }
            });
        }
        if ($quarters = $datatables->request->get('quarters')) {
            $datatables->where(function ($query) use($quarters) {
                foreach ($quarters as $quarter) {
                    $query->orWhereRaw('MONTH(Date) = ' . $quarter);
                }
            });
        }
        if ($years = $datatables->request->get('years')) {
            $datatables->where(function ($query) use($years) {
                foreach ($years as $year) {
                    $query->orWhereRaw('YEAR(Date) = ' . $year);
                }
            });
        }
        return $datatables->make(true);
    }
开发者ID:clcarver,项目名称:FacBI,代码行数:32,代码来源:ITPAPI.php


示例6: handle

 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $weixin = $request->session()->get('wechat.oauth_user');
     // 不接受无信用的凭证
     if (empty($weixin['id']) || strlen($weixin['id']) !== 28) {
         return abort(405);
     }
     // 生成一个随机的userKEY用于会话验证
     // 将该session的过期时间设置为比access_token
     // 的refresh时长多10s,一旦access_token刷新,
     // userKEY的值会重新计算并存储
     $token = $weixin['token'];
     $refresh = $token['refresh_token'];
     $expires = $token['expires_in'];
     // 假设用户数据已经存在于数据库中
     $user = Weixin_User::getFullyUserInfoWithOpenID($token['openid']);
     if (empty($user)) {
         $user = Weixin_User::storeNewUserInfo(new Weixin_User(), $weixin->toArray());
     }
     $user_id = $user->user_id;
     $key = 'jk_session:' . $user_id . ':userKEY';
     // 存储当前会话消息
     $request->session()->put('jukebox_user', $user_id);
     // 计算并存储userKEY
     if (!\PRedis::command('get', [$key])) {
         \PRedis::command('setex', [$key, intval($expires) + 10, str_limit($refresh, 5) . str_random(1)]);
     }
     return $next($request);
 }
开发者ID:RedrockTeam,项目名称:jukebox,代码行数:36,代码来源:Authenticate.php


示例7: store

 public function store($data, $type = null)
 {
     $this->user_id = Auth::id();
     $this->question_id = $data['question'];
     $this->slug = Tools::slug($data['title']);
     $this->title = $data['title'];
     $this->type = $data['post_type'];
     $this->selected_option = $data['option'];
     switch ($type) {
         case 'text':
             $this->content = Purifier::clean($data['content']);
             $description = $data['content'];
             break;
         case 'link':
         case 'video':
         case 'vine':
             $this->content = Purifier::clean($data['link'], 'noHtml');
             $description = $data['description'];
             break;
         case 'audio':
         case 'photo':
             $file = Input::file('post_file');
             $this->post_file_ext = $file->getClientOriginalExtension();
             $this->post_file = $this->savePostFile($file, $type, Auth::id());
             $description = $data['content'];
             break;
     }
     $this->description = str_limit(Purifier::clean($description, 'noHtml'), 255, '');
     $this->save();
     return ['id' => $this->id, 'slug' => $this->slug];
 }
开发者ID:anthrotech,项目名称:laravel_sample,代码行数:31,代码来源:Post.php


示例8: __construct

 function __construct()
 {
     View::share('latestActivePosts', (new LatestActivePosts())->get());
     $this->meta = new Meta();
     $this->meta->set(['title' => 'Wordpress Killed Me - Your place to rant about Wordpress', 'description' => 'Trouble with Wordpress? Here you are at the right place to scream it out to the world.', 'keywords' => ['wordpress', 'cms', 'only for blogs', 'hate', 'rant', 'fail'], 'image' => 'http://wordpresskilled.me/img/hp-image.png', 'og' => ['site_name' => 'Wordpress Killed Me', 'title' => 'Wordpress Killed Me - Your place to rant about Wordpress', 'description' => 'Trouble with Wordpress? Here you are at the right place to scream it out to the world.', 'keywords' => ['wordpress', 'cms', 'only for blogs', 'hate', 'rant', 'fail'], 'image' => 'http://wordpresskilled.me/img/hp-image.png'], 'twitter' => ['card' => 'summary', 'site' => '@wpkilledme', 'title' => 'Wordpress Killed Me - Your place to rant about Wordpress', 'description' => str_limit('Trouble with Wordpress? Here you are at the right place to scream it out to the world.', 180), 'image' => 'http://wordpresskilled.me/img/twitter-image.png']]);
     View::share('meta', $this->meta);
 }
开发者ID:bastienbot,项目名称:wordpresskilled.me,代码行数:7,代码来源:Controller.php


示例9: description_trim

function description_trim($description, $limit = 500, $end = '...')
{
    $description = strip_tags(str_limit($description, $limit, $end));
    $description = str_replace("  ", "", $description);
    $description = str_replace("\n", "", $description);
    return $description;
}
开发者ID:kpaxer,项目名称:laravel-blog,代码行数:7,代码来源:helpers.php


示例10: onSaving

 public function onSaving(Topic $topic)
 {
     $topic->title = Purifier::clean($topic->title, 'title');
     $topic->body_original = Purifier::clean(trim($topic->body), 'body');
     $topic->body = app('markdown')->text($topic->body_original);
     $topic->excerpt = str_limit(trim(preg_replace('/\\s+/', ' ', strip_tags($topic->body))), 200);
 }
开发者ID:jianoll,项目名称:phphub-server,代码行数:7,代码来源:TopicListener.php


示例11: buildFileName

 public function buildFileName($invoice = false)
 {
     $key = $invoice ? 'invoice' : 'paper';
     if ($this->files[$key . '_name']) {
         #if already build
         return $this->files[$key . '_name'];
     }
     if (!request()->file($this->files[$key])) {
         return '';
     }
     $ext = request()->file($this->files[$key])->getClientOriginalExtension();
     $name = request()->file($this->files[$key])->getClientOriginalName();
     $name = str_replace('.' . $ext, '', $name);
     #check if name is bigger then 90 chars and cut + remove ... from string
     $name = str_limit($name, 90);
     if (substr($name, -1) == '.') {
         $name = substr($name, 0, -3);
     }
     $userName = explode(' ', auth()->user()->name);
     $name .= '_' . $userName[0][0] . $userName[1][0];
     #get user letters
     if ($invoice) {
         $name .= 'I';
         #add i before number
     }
     $name .= rand(1, 999);
     $name .= '.' . $ext;
     #add extension
     if (File::exists(self::$path . $name)) {
         $name = $this->buildFileName($invoice);
     }
     $this->files[$key . '_name'] = $name;
     return $name;
 }
开发者ID:Tisho84,项目名称:conference,代码行数:34,代码来源:PaperClass.php


示例12: postUpdate

 public function postUpdate(Requests\Admin\ArticleRequest $request, $type, $act, $id = 0)
 {
     $article = new Article();
     if ($act == 'edit') {
         $article = Article::find($id);
     }
     $article->user_id = \Auth::id();
     $article->node_id = $request->input('node');
     $article->title = $request->input('title');
     $article->seo_title = $request->input('seo_title');
     $article->description = $request->input('description');
     $article->keywords = $request->input('keywords');
     $article->type = $request->input('type');
     $article->image = $request->input('get_image');
     $article->outline = $request->input('outline') ?: str_limit(strip_tags($request->input('content')));
     $article->content = $request->input('content');
     $article->order = $request->input('order');
     $article->views = $request->input('views');
     $article->hot = $request->input('hot') ? 1 : 0;
     $article->status = $request->input('status') ? 1 : 0;
     $article->recommend = $request->input('recommend') ? 1 : 0;
     $article->show_index = $request->input('show_index') ? 1 : 0;
     if ($article->save()) {
         $info = ['from' => 'update', 'status' => 'success'];
         j4flash($info);
         return redirect('admin/article/index/' . $type);
     } else {
         return redirect()->back()->withErrors(['err' => lang('submit failed')])->withInput();
     }
 }
开发者ID:jay4497,项目名称:j4cms,代码行数:30,代码来源:ArticleController.php


示例13: createPost

 public function createPost(Requests\Bins\CreateBin $request)
 {
     $description = $request->has('description') && trim($request->input('description')) != '' ? $request->input('description') : null;
     $bin = Bin::create(['user_id' => auth()->user()->getAuthIdentifier(), 'title' => $request->input('title'), 'description' => $description, 'visibility' => $request->input('visibility')]);
     if ($bin->isPublic()) {
         $status = 'Bin: #laravel ' . $bin->url() . ' ' . $bin->title;
         Twitter::postTweet(['status' => str_limit($status, 135), 'format' => 'json']);
         $bin->tweeted = true;
         $bin->save();
     }
     $bin->versions()->sync($request->input('versions'));
     $files = [];
     foreach ($request->input('name') as $key => $value) {
         $files[$key]['name'] = $value;
     }
     foreach ($request->input('language') as $key => $value) {
         $files[$key]['language'] = $value;
     }
     foreach ($request->input('code') as $key => $value) {
         $files[$key]['code'] = $value;
     }
     foreach ($files as $item) {
         $type = Type::where('css_class', $item['language'])->first();
         $bin->snippets()->create(['type_id' => $type->id, 'name' => $item['name'], 'code' => $item['code']]);
     }
     session()->flash('success', 'Bin created successfully!');
     return redirect()->route('bin.code', $bin->getRouteKey());
 }
开发者ID:everdaniel,项目名称:LaraBin,代码行数:28,代码来源:BinController.php


示例14: __construct

 /**
  * @param string $title
  * @param string $tinyIcon
  * @param string $largeIcon
  * @param string $locationName
  */
 public function __construct($title, $tinyIcon, $largeIcon, $locationName)
 {
     $this->title = $title;
     $this->tinyIcon = $tinyIcon;
     $this->largeIcon = $largeIcon;
     $this->locationName = str_limit($locationName, 256);
 }
开发者ID:logbon72,项目名称:pinpusher,代码行数:13,代码来源:Weather.php


示例15: getSummaryAttribute

 public function getSummaryAttribute()
 {
     if (empty($this->summary)) {
         return str_limit(strip_tags($this->content), 1200);
     }
     return;
 }
开发者ID:sordev,项目名称:bootup,代码行数:7,代码来源:Content.php


示例16: index

 public function index($id)
 {
     $post = $this->postRepository->findById($id);
     if (!$post or !$post->present()->canView()) {
         if (\Request::ajax()) {
             return '';
         }
         return $this->theme->section('error-page');
     }
     $this->theme->share('site_description', $post->text ? \Str::limit($post->text, 100) : \Config::get('site_description'));
     $this->theme->share('ogUrl', \URL::route('post-page', ['id' => $post->id]));
     if ($post->text) {
         $this->theme->share('ogTitle', \Str::limit($post->text, 100));
     }
     if ($post->present()->hasValidImage()) {
         foreach ($post->present()->images() as $image) {
             $this->theme->share('ogImage', \Image::url($image, 600));
         }
     }
     $ad = empty($post->text) ? trans('post.post') : str_limit($post->text, 60);
     $design = [];
     if ($post->page_id) {
         $design = $post->page->present()->readDesign();
     } elseif ($post->community_id) {
         $design = $post->community->present()->readDesign();
     } else {
         $design = $post->user->present()->readDesign();
     }
     return $this->render('post.page', ['post' => $post], ['title' => $this->setTitle($ad), 'design' => $design]);
 }
开发者ID:adamendvy89,项目名称:intifadah,代码行数:30,代码来源:PostController.php


示例17: getExcerptAttribute

 /**
  * The pages short content
  *
  * @return mixed null|string
  */
 public function getExcerptAttribute()
 {
     if (array_has($this->attributes, 'body')) {
         return str_limit(strip_tags($this->attributes['body']), 200);
     }
     return null;
 }
开发者ID:adminarchitect,项目名称:pages,代码行数:12,代码来源:Page.php


示例18: handle

 /**
  * Update podcast items
  *
  * @return mixed
  */
 public function handle()
 {
     $uniquePodcasts = DB::table('podcasts')->select('id', 'feed_url', 'machine_name')->groupBy('machine_name')->get();
     foreach ($uniquePodcasts as $podcast) {
         $usersSubscribedToThisPodcast = DB::table('podcasts')->select('user_id', 'id as podcast_id')->where('machine_name', '=', $podcast->machine_name)->get();
         $items = Feeds::make($podcast->feed_url)->get_items();
         // Calculate 48 hours ago
         $yesterday = time() - 24 * 2 * 60 * 60;
         foreach ($items as $item) {
             $itemPubDate = $item->get_date();
             if ($item->get_date('U') > $yesterday) {
                 // new items
                 foreach ($usersSubscribedToThisPodcast as $subscriber) {
                     $podcastItemsCount = DB::table('items')->select('user_id', 'title', 'podcast_id')->where('title', '=', strip_tags($item->get_title()))->where('user_id', '=', $subscriber->user_id)->where('podcast_id', '=', $subscriber->podcast_id)->count();
                     // if this item is not already in the DB
                     if ($podcastItemsCount == 0) {
                         Item::create(['user_id' => $subscriber->user_id, 'title' => strip_tags($item->get_title()), 'description' => strip_tags(str_limit($item->get_description(), 100)), 'published_at' => $item->get_date('Y-m-d'), 'url' => $item->get_permalink(), 'audio_url' => $item->get_enclosure()->get_link(), 'podcast_id' => $subscriber->podcast_id]);
                     }
                 }
             } else {
                 break;
             }
         }
     }
 }
开发者ID:MehmetNuri,项目名称:Podcastwala,代码行数:30,代码来源:UpdatePodcastItems.php


示例19: publishDraftCreate

 public function publishDraftCreate($article_id)
 {
     $input = Input::all();
     $validator = Validator::make($input, DraftArticle::$rules, DraftArticle::$validatorMessages);
     if ($validator->passes()) {
         $model = DraftArticle::where('id', '=', $article_id)->first();
         $model->title = Input::get('title');
         $model->digest = str_limit(strip_tags(Input::get('content')), 30, '...');
         $pictures = $model->pictures;
         if (!$pictures->isEmpty()) {
             $model->cover = $pictures->first()->path;
         } else {
             $model->cover = "/static/img/nopic.png";
         }
         $model->status = '002';
         $model->content = Input::get('content');
         if ($model->save()) {
             $response['success'] = true;
         } else {
             $response['success'] = false;
             $response['message'] = '发布失败。';
         }
     } else {
         $response['success'] = false;
         $response['message'] = $validator->messages()->first();
     }
     return Response::json($response);
 }
开发者ID:Kangaroos,项目名称:oneshike,代码行数:28,代码来源:ArticleController.php


示例20: all_with_info

 /**
  * Return an array with character information.
  * This includes the key info as well as the
  * extended information such as type/expiry etc.
  *
  * @return array
  */
 public function all_with_info()
 {
     $response = [];
     foreach (EveApiKeyModel::all() as $key) {
         $response[$key->key_id] = ['enabled' => $key->enabled, 'user_id' => $key->user_id, 'key_id' => $key->key_id, 'v_code' => str_limit($key->v_code, 15), 'access_mask' => $key->info ? $key->info->accessMask : null, 'type' => $key->info ? $key->info->type : null, 'expires' => $key->info ? $key->info->expires : null, 'last_error' => $key->last_error, 'characters' => count($key->characters) > 0 ? implode(', ', $key->characters->lists('characterName')->all()) : null];
     }
     return $response;
 }
开发者ID:warlof,项目名称:services,代码行数:15,代码来源:EveApiKey.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP str_pad函数代码示例发布时间:2022-05-23
下一篇:
PHP str_len函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap