TextObject.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:2k
- <?php
- class TextObject extends BaseObject {
- Function TextObject() {
- $this->BaseObject( 'TextObject' );
- }
- Function WrapText( $text_to_wrap, $line_len = 80, $line_boundary = "n" ) {
- $my_lines = Array();
- $my_lines = split( $line_boundary, $text_to_wrap );
- for( $i = 0; $i < count( $my_lines ); $i++ ) {
- $my_lines[ $i ] = $this->WrapLine(
- $my_lines[ $i ],
- $line_len,
- $line_boundary
- );
- }
- return join( "n", $my_lines );
- }
- Function WrapLine( $text_to_wrap, $line_len = 80, $line_boundary = "n" ) {
- $text_len = strlen( $text_to_wrap );
- if ( $text_len > $line_len ) {
- $all_words = Array();
- $this_line = '';
- $new_line = '';
- $this_len = 0;
- $all_words = split( ' ', $text_to_wrap );
- for( $i = 0; $i < count( $all_words ); $i++ ) {
- $cur_word = $all_words[ $i ];
- $cur_word_len = strlen( $cur_word );
- if ( ( $this_len + $cur_word_len ) > $line_len ) {
- $this_len = $line_len + 100;
- if ( $new_line != '' ) { $new_line .= ' '; }
- $new_line .= $cur_word;
- } else {
- if ( $this_line != '' ) { $this_line .= ' '; }
- $this_line .= $cur_word;
- $this_len = strlen( $this_line );
- }
- }
- $this_line .= $line_boundary;
- $new_line = $this->WrapLine( $new_line, $line_len, $line_boundary );
- return $this_line . $new_line;
- } else {
- return $text_to_wrap;
- }
- }
- Function PhpOptimize( $file_name ) {
- }
- }
- ?>