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


PHP str_limit函数代码示例

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


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


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