• Aaack. I can’t seem to figure out what I’m doing wrong. I’m trying to truncate my Nextgen gallery image descriptions and I’ve managed to truncate them, but it breaks the rest of my page. Is there anyone who could look at this piece of my code and tell me what the heck I’m doing wrong? Thanks in advance.

    <?php foreach ( $images as $image ) : ?>
    ...stuff...
    
    <?php
    function truncate($string, $del) {
      $len = strlen($string);
      if ($len > $del) {
        $new = substr($string,0,$del)."...";
        return $new;
      }
      else return $string;
    }
    
    $arg = "$image->description";
    
    ?>						
    
    <p><?php echo truncate($arg, 130)."n"; ?></p>	
    
    ...more stuff....
    <?php endforeach; ?>
Viewing 1 replies (of 1 total)
  • Thread Starter mfal55

    (@mfal55)

    I also tried this method, but also breaks the page

    <?php
    function truncate($string, $max = 20, $replacement = '')
    
    {
    
        if (strlen($string) <= $max)
        {
            return $string;
        }
        $leave = $max - strlen ($replacement);
        return substr_replace($string, $replacement, $leave);
    }
    $descript = $image->description;
    echo truncate($descript,10,'...');
    ?>

    My php must be wrong in some way, but my knowledge in this area is super limited.
    Any help is greatly appreciated.

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘Truncate Nextgen description’ is closed to new replies.