TextObject.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:2k
源码类别:

WEB邮件程序

开发平台:

PHP

  1. <?php
  2. class TextObject extends BaseObject {
  3.    Function TextObject() {
  4.       $this->BaseObject( 'TextObject' );
  5.    }
  6.    Function WrapText( $text_to_wrap, $line_len = 80, $line_boundary = "n" ) {
  7.       $my_lines = Array();
  8.       $my_lines = split( $line_boundary, $text_to_wrap );
  9.       for( $i = 0; $i < count( $my_lines ); $i++ ) {
  10.          $my_lines[ $i ] = $this->WrapLine( 
  11.             $my_lines[ $i ],
  12.             $line_len,
  13.             $line_boundary
  14.          );
  15.       }
  16.       return join( "n", $my_lines );
  17.    }
  18.    Function WrapLine( $text_to_wrap, $line_len = 80, $line_boundary = "n" ) {
  19.       $text_len = strlen( $text_to_wrap );
  20.       if ( $text_len > $line_len ) {
  21.          $all_words = Array();
  22.          $this_line = '';
  23.          $new_line  = '';
  24.          $this_len  = 0;
  25.          $all_words = split( ' ', $text_to_wrap  );
  26.          for( $i = 0; $i < count( $all_words ); $i++ ) {
  27.             $cur_word     = $all_words[ $i ];
  28.             $cur_word_len = strlen( $cur_word );
  29.             if ( ( $this_len + $cur_word_len ) > $line_len ) {
  30.                $this_len = $line_len + 100;
  31.                if ( $new_line != '' ) { $new_line .= ' '; }
  32.                $new_line .= $cur_word;
  33.             } else {
  34.                if ( $this_line != '' ) { $this_line .= ' '; }
  35.                $this_line .= $cur_word;
  36.                $this_len     = strlen( $this_line );
  37.             }
  38.          }
  39.          $this_line .= $line_boundary;
  40.          $new_line  = $this->WrapLine( $new_line, $line_len, $line_boundary );
  41.          return $this_line . $new_line;
  42.       } else {
  43.          return $text_to_wrap;
  44.       }
  45.    }
  46.    Function PhpOptimize( $file_name ) {
  47.    }
  48. }
  49. ?>