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


PHP TextHelper::truncate方法代码示例

本文整理汇总了PHP中TextHelper::truncate方法的典型用法代码示例。如果您正苦于以下问题:PHP TextHelper::truncate方法的具体用法?PHP TextHelper::truncate怎么用?PHP TextHelper::truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextHelper的用法示例。


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

示例1: TextHelper

    function test_for_TextHelper()
    {
        require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'text_helper.php';
        $text = new TextHelper();
        $this->assertEqual($text->truncate('truncates the last ten characters', 10, '...'), 'truncates the...');
        $this->assertEqual($text->highlight('I am highlighting the phrase', 'highlighting'), 'I am <strong class="highlight">highlighting</strong> the phrase');
        $this->assertEqual($text->highlight('I am highlighting the phrase', array('highlighting', 'the')), 'I am <strong class="highlight">highlighting</strong> <strong class="highlight">the</strong> phrase');
        $this->assertEqual($text->excerpt("hello my world", "my", 3), '...lo my wo...');
        $this->assertEqual($text->excerpt("hello my world", "my", 5, '---'), '---ello my worl---');
        $this->assertEqual($text->pluralize(0, 'Property', 'Properties'), 'Properties');
        $this->assertEqual($text->pluralize(1, 'Property'), 'Property');
        $this->assertEqual($text->pluralize(2, 'Property'), 'Properties');
        $this->assertEqual($text->word_wrap('Wraps a string to a given number of characters', 20), "Wraps a string to a\ngiven number of\ncharacters");
        $this->assertEqual($text->textilize('__Wraps__'), '<p><i>Wraps</i></p>');
        $this->assertEqual($text->textilize('_Wraps_'), '<p><em>Wraps</em></p>');
        $this->assertEqual($text->textilize('p[no]. paragraph'), '<p lang="no">paragraph</p>');
        $this->assertEqual($text->textilize('h3{color:red}. header 3'), '<h3 style="color:red;">header 3</h3>');
        $this->assertEqual($text->textilize_without_paragraph('__Wraps__'), '<i>Wraps</i>');
        $this->assertEqual($text->textilize_without_paragraph('p[no]. paragraph'), 'paragraph');
        require_once AK_LIB_DIR . DS . 'AkActionView' . DS . 'helpers' . DS . 'tag_helper.php';
        $this->assertEqual($text->simple_format("Test\r\n"), "<p>Test\n</p>");
        $this->assertEqual($text->simple_format("Test\n"), "<p>Test\n</p>");
        $this->assertEqual($text->simple_format("Test\r"), "<p>Test\n</p>");
        $this->assertEqual($text->simple_format("Test\n\nTest"), "<p>Test</p>\n<p>Test</p>");
        $this->assertEqual($text->simple_format("Test\n\n"), "<p>Test</p><br /><br />");
        $this->assertEqual($text->simple_format("Test\n\n\n\n\n\n"), "<p>Test</p><br /><br />");
        $this->assertEqual($text->auto_link_email_addresses('sending an email to salavert@example.com and to hilario@example.com'), 'sending an email to <a href=\'mailto:salavert@example.com\'>salavert@example.com</a> and to <a href=\'mailto:hilario@example.com\'>hilario@example.com</a>');
        $this->assertEqual($text->auto_link_email_addresses('salavert@@example.com'), 'salavert@@example.com');
        $this->assertEqual($text->auto_link_email_addresses('email sent to salavert@example.c'), 'email sent to <a href=\'mailto:salavert@example.c\'>salavert@example.c</a>');
        $this->assertEqual($text->auto_link_urls('http://www.thebigmover.com'), '<a href="http://www.thebigmover.com">http://www.thebigmover.com</a>');
        $this->assertEqual($text->auto_link_urls('www.thebigmover.com'), '<a href="http://www.thebigmover.com">www.thebigmover.com</a>');
        //$this->assertEqual($text->auto_link_urls('www.thebigmover.com nested www.thebigmover.com/search'),'<a href="http://www.thebigmover.com">www.thebigmover.com</a> nested <a href="http://www.thebigmover.com/search">www.thebigmover.com/search</a>');//, 'Failed auto_link_urls nested url');
        $this->assertEqual($text->auto_link_urls('Visit http://www.thebigmover.com now'), 'Visit <a href="http://www.thebigmover.com">http://www.thebigmover.com</a> now');
        $this->assertEqual($text->auto_link_urls('Visit http://www.thebigmover.com now and later http://www.akelos.com'), 'Visit <a href="http://www.thebigmover.com">http://www.thebigmover.com</a> now and later <a href="http://www.akelos.com">http://www.akelos.com</a>');
        $this->assertEqual($text->strip_links('email sent to <a href=\'mailto:salavert@example.c\'>salavert@example.c</a>'), 'email sent to salavert@example.c');
        $this->assertEqual($text->strip_links('sending an email to <a href="mailto:salavert@example.com">salavert@example.com</a> and to <a href="mailto:hilario@example.com">hilario@example.com</a>'), 'sending an email to salavert@example.com and to hilario@example.com');
        //, 'Failed auto_link_email_addresses test');
        $this->assertEqual($text->strip_selected_tags('sending <b>email</b> to <a href="mailto:salavert@example.com">salavert@example.com</a>', 'a', 'b'), 'sending email to salavert@example.com');
        //, 'Failed auto_link_email_addresses test');
        $this->assertEqual($text->strip_selected_tags('sending <b>email</b> to <a href="mailto:salavert@example.com">salavert@example.com</a>', array('a', 'b')), 'sending email to salavert@example.com');
        //, 'Failed auto_link_email_addresses test');
        $this->assertEqual($text->strip_selected_tags('sending <b>email</b> to <a href="mailto:salavert@example.com">salavert@example.com</a>', 'a'), 'sending <b>email</b> to salavert@example.com');
        //, 'Failed auto_link_email_addresses test');
        $this->assertEqual($text->auto_link('email sent to salavert@example.com from http://www.thebigmover.com', 'all'), 'email sent to <a href=\'mailto:salavert@example.com\'>salavert@example.com</a> from <a href="http://www.thebigmover.com">http://www.thebigmover.com</a>');
        $this->assertEqual($text->auto_link('email sent to salavert@example.com', 'email_addresses'), 'email sent to <a href=\'mailto:salavert@example.com\'>salavert@example.com</a>');
        $this->assertEqual($text->auto_link('email sent from http://www.thebigmover.com', 'urls'), 'email sent from <a href="http://www.thebigmover.com">http://www.thebigmover.com</a>');
        $this->assertEqual($text->strip_tags('<a href="nowhere" onclick="javascript:alert(\'oops\');">link</a>'), 'link');
        $this->assertEqual($text->markdown('> ## This is a header.
> 
> 1.   This is the first list item.
> 2.   This is the second list item.
> 
> Here\'s some example code:
> 
>     return shell_exec("echo $input | $markdown_script");'), '<blockquote>
  <h2>This is a header.</h2>
  
  <ol>
  <li>This is the first list item.</li>
  <li>This is the second list item.</li>
  </ol>
  
  <p>Here\'s some example code:</p>

<pre><code>return shell_exec("echo $input | $markdown_script");
</code></pre>
</blockquote>');
    }
开发者ID:joeymetal,项目名称:v1,代码行数:68,代码来源:text_helper.php

示例2: truncate

 /**
  * shorten text (either exact or intelligent)
  * @param array $options
  * - ending, exact, html
  * 2009-08-08 ms
  */
 public function truncate($text, $length = 100, $options = array())
 {
     $defaults = array('ending' => CHAR_HELLIP);
     $options = array_merge($defaults, $options);
     return parent::truncate($text, $length, $options);
 }
开发者ID:robksawyer,项目名称:grabitdown,代码行数:12,代码来源:FormatHelper.php

示例3: search

 function search()
 {
     $this->set('title_for_layout', 'Sökresultat');
     if (!empty($this->params['form']) || !empty($this->passedArgs) || empty($this->passedArgs) && empty($this->params['form'])) {
         App::import('Helper', 'Text');
         $text = new TextHelper();
         $args = array_merge($this->params['form'], $this->passedArgs);
         extract($args);
         $search_params = array();
         if (isset($count)) {
             $areas_text = "";
             if (isset($types) && !empty($types)) {
                 $search_params['types'] = explode(',', $types);
             }
             if (isset($areas) && !empty($areas)) {
                 $area_ids = explode(',', $areas);
                 $search_params['areas'] = $area_ids;
                 //get the names of the municipal areas
                 $area_names = $this->ObjectMunicipalArea->find('list', array('conditions' => array('id' => $area_ids), 'recursive' => -1, 'fields' => 'ObjectMunicipalArea.name'));
                 $areas_text = implode(', ', $area_names);
                 $areas_text = rtrim($areas_text, ',');
                 $areas_text = $text->truncate($areas_text, 50);
             }
             if (isset($rooms) && !empty($rooms)) {
                 $search_params['rooms'] = explode(',', $rooms);
             }
             if (isset($size) && !empty($size)) {
                 $search_params['size'] = explode(',', $size);
             }
             if (isset($price) && !empty($price)) {
                 $search_params['price'] = explode(',', $price);
             }
             $options = array('fields' => 'ObjectItem.id', 'recursive' => -1);
             $objects = $this->ObjectItem->search($search_params, $options);
             $object_ids = Set::extract('/ObjectItem/id', $objects);
             $this->Session->write('SearchObjectIds', $object_ids);
             Configure::write('debug', 0);
             $this->autoRender = false;
             $this->RequestHandler->respondAs('json');
             $ret['count'] = count($objects);
             $ret['filter_text'] = $text->truncate($this->ObjectItem->filterText, 55);
             $ret['areas_text'] = $areas_text;
             $this->Session->write('SearchCounter', $ret['count']);
             $this->Session->write('SearchUrl', sprintf('sok/types:%s/areas:%s/rooms:%s/size:%s/price:%s#resultat', $types, $areas, $rooms, $size, $price));
             echo json_encode($ret);
         } else {
             $objects = array();
             if ($this->Session->check('SearchObjectIds')) {
                 $object_ids = $this->Session->read('SearchObjectIds');
             } else {
                 $objects = $this->ObjectItem->find('all');
                 $object_ids = Set::extract('/ObjectItem/id', $objects);
             }
             $sort = isset($sort) ? $sort : false;
             $direction = isset($direction) ? $direction : false;
             $map = isset($map) ? $map : false;
             if (!$map) {
                 $conditions['ObjectItem.is_active'] = '1';
                 $conditions['ObjectItem.id'] = $object_ids;
                 $this->paginate['contain'] = array('ObjectItemImage', 'ObjectMunicipal', 'ObjectArea' => array('ObjectInfoArea'));
                 $this->paginate['recursive'] = 2;
                 $this->paginate['limit'] = 5;
                 $this->paginate['order'] = array('ObjectItem.created' => 'desc');
                 $this->paginate['conditions'] = $conditions;
                 $objects = $this->paginate('ObjectItem');
             }
             $hitta_map_base_url = Configure::read('Settings.hitta_map_base_url');
             $this->set('type', false);
             $this->set('objects', $objects);
             $this->set('map', $map);
             $this->set('sort', $sort);
             $this->set('direction', $direction);
             $this->set('params', $args);
             $this->set(compact('hitta_map_base_url'));
             $this->render('/object_items/bostad');
         }
     }
 }
开发者ID:EnkelMagnus,项目名称:m2,代码行数:78,代码来源:object_items_controller.php


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