Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Limitar la Cantidad de Texto a Mostrar

Estas en el tema de Limitar la Cantidad de Texto a Mostrar en el foro de PHP en Foros del Web. hola... quisiera limitar la cantidad de texto a mostrar .. no se php por eso pido ayuda... agregue un ubstr($string, 0, 150); (linea 44) .. ...
  #1 (permalink)  
Antiguo 02/07/2016, 09:12
 
Fecha de Ingreso: junio-2008
Mensajes: 82
Antigüedad: 15 años, 10 meses
Puntos: 2
Limitar la Cantidad de Texto a Mostrar

hola... quisiera limitar la cantidad de texto a mostrar .. no se php por eso pido ayuda... agregue un ubstr($string, 0, 150); (linea 44) .. la linea 43 es la que me muestra el intro texto que quiero limitar.. espero alguno pueda darme una mano.. quisiera limitarlo a unos 150 caracteres ... o ir probando hasta ajustar y que no me exceda a lo que necesito... saludos...


Código PHP:
Ver original
  1. <?php
  2. /**
  3.  
  4.  */
  5.  
  6. defined('_JEXEC') or die;?>
  7. <?php
  8. // Create a shortcut for params.
  9. $params = $this->item->params;
  10. JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
  11. $canEdit = $this->item->params->get('access-edit');
  12.  
  13. ?>
  14. <?php if ($this->item->state == 0) : ?>
  15.     <span class="label label-warning"><?php echo JText::_('JUNPUBLISHED'); ?></span>
  16. <?php endif; ?>
  17.  
  18.     <?php //intro images ?>
  19.     <?php echo JLayoutHelper::render('content.intro_image', $this->item); ?>
  20.  
  21.     <div class="article-text">
  22.         <?php echo JLayoutHelper::render('content.blog_style_default_item_title', $this->item); ?>
  23.         <?php echo JLayoutHelper::render('content.icons', array('params' => $params, 'item' => $this->item, 'print' => false)); ?>
  24.        
  25.         <aside class="article-aside">
  26.             <?php // Todo Not that elegant would be nice to group the params ?>
  27.             <?php $useDefList = ($params->get('show_modify_date') || $params->get('show_publish_date') || $params->get('show_create_date')
  28.                 || $params->get('show_hits') || $params->get('show_category') || $params->get('show_parent_category') || $params->get('show_author') ); ?>
  29.  
  30.             <?php if ($useDefList) : ?>
  31.                 <?php echo JLayoutHelper::render('content.info_block.block', array('item' => $this->item, 'params' => $params, 'position' => 'above')); ?>
  32.             <?php endif; ?>
  33.         </aside>
  34.  
  35.     <?php if (!$params->get('show_intro')) : ?>
  36.             <?php echo $this->item->event->afterDisplayTitle; ?>
  37.     <?php endif; ?>
  38.  
  39.     <?php echo $this->item->event->beforeDisplayContent; ?>
  40.  
  41.     <?php if ($params->get('show_intro')) : ?>
  42.         <div class="article-intro">
  43.             <?php echo $this->item->introtext; ?>
  44.             <?php echo substr($string, 0, 100);?>            
  45.         </div>
  46.     <?php endif; ?>
  47.  
  48.    
  49.  
  50.     <?php if ($params->get('show_readmore') && $this->item->readmore) :
  51.         if ($params->get('access-view')) :
  52.             $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid));
  53.         else :
  54.             $menu = JFactory::getApplication()->getMenu();
  55.             $active = $menu->getActive();
  56.             $itemId = $active->id;
  57.             $link1 = JRoute::_('index.php?option=com_users&view=login&Itemid=' . $itemId);
  58.             $returnURL = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid));
  59.             $link = new JURI($link1);
  60.             $link->setVar('return', base64_encode($returnURL));
  61.         endif; ?>
  62.  
  63.         <a class="button" href="<?php echo $link; ?>">
  64.            
  65.         <?php if (!$params->get('access-view')) :
  66.             echo JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
  67.         elseif ($readmore = $this->item->alternative_readmore) :
  68.             echo $readmore;
  69.             if ($params->get('show_readmore_title', 0) != 0) :
  70.             echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
  71.             endif;
  72.         elseif ($params->get('show_readmore_title', 0) == 0) :
  73.             echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
  74.         else :
  75.             echo JText::_('COM_CONTENT_READ_MORE');
  76.             echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
  77.         endif; ?>
  78.        
  79.            
  80.         </a>
  81.  
  82.     <?php endif; ?>
  83.    
  84.    
  85.     </div>
  86.    
  87. <?php if ($this->item->state == 0) : ?>
  88. </div>
  89. <?php endif; ?>
  90.  
  91. <?php echo $this->item->event->afterDisplayContent; ?>
  #2 (permalink)  
Antiguo 02/07/2016, 22:21
 
Fecha de Ingreso: agosto-2012
Ubicación: M.
Mensajes: 2.031
Antigüedad: 11 años, 8 meses
Puntos: 52
Respuesta: Limitar la Cantidad de Texto a Mostrar

¿Y cual es el problema?

Código PHP:
Ver original
  1. <?php echo substr($this->item->introtext, 0, 100);?>
__________________
a veces creemos que es algo básico pero al profundizar nos damos cuenta que estábamos tocando solo la cola de la culebra

Etiquetas: cantidad, html, limitar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:26.