Help for this page

Select Code to Download


  1. or download this
    if( length($string) > 0 ) {
      # do something
    }
    
  2. or download this
    if( length($string) > 50 ) {
      # cut the string and either add ... to show it was truncated.
      $string = substr( $string, 0, 47 ) . '...';
      # alternatively, or not
      $string = substr( $string, 0, 50 );
    }
    
  3. or download this
    my $MAXLEN = 50;
    if( length($string) > $MAXLEN ) {
      # cut the string and either add ... to show it was truncated.
    ...
      # alternatively, or not
      $string = substr( $string, 0, $MAXLEN );
    }