how to limit the amount of caracters? help...

Discussion in 'PHP' started by s.jns, Oct 30, 2010.

  1. #1
    Hi,
    If someone here is willing to help me I would really appreciate
    how to limit the amount of characters in the following php code, let say max 90 characters then should click read more link for details?

    		$this->data['text_read_more'] = $this->language->get('text_read_more');
    		$this->data['news'] = array();
    		$results = $this->model_catalog_news->getNewsShorts($this->config->get('news_limit'));
    		foreach ($results as $result) {
    			$short_description = explode('.', html_entity_decode($result['description'])); 
    			$this->data['news'][] = array(
    				'title'             => $result['title'],
    				'short_description' => $short_description[0],
    				'href'              => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=page/news&news_id=' . $result['news_id'])
    			);
    		}
    PHP:
    the html code:
          <div style="border-bottom: 1px solid #DDDDDD; margin-bottom: 8px;">
            <?php echo $news_story['short_description']; ?> &hellip; <a href="<?php echo $news_story['href']; ?>"><?php echo $text_read_more; ?></a></p>
          </div>
    Code (markup):
    Thanks in advance
     
    s.jns, Oct 30, 2010 IP
  2. yogabalan

    yogabalan Member

    Messages:
    106
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #2
    substr("$str",0,90)
     
    yogabalan, Oct 30, 2010 IP
  3. KingOle

    KingOle Peon

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    $this->data['text_read_more'] = substr($this->data['text_read_more'],0,90) . " ... [<a href=''>Read More</a>]";
    
    PHP:
    Something like this?
     
    KingOle, Oct 30, 2010 IP
  4. s.jns

    s.jns Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    Thank You, this already solved
     
    s.jns, Nov 14, 2010 IP