PHP code example of wangqs / cut_elegant_string

1. Go to this page and download the library: Download wangqs/cut_elegant_string library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wangqs / cut_elegant_string example snippets


    
    $config = [
		'endMark' => [ '。' , '?' , '!' ] ,
		'length'  => 150
	];
	
	$cut = new StringCut( $config );
    
    echo $cut->get('你的长字符串...')->toArray();
    

    
    echo StringCut::init()
                    ->length( 150 )
                    ->get('你的长字符串...')
                    ->toJson();
    

    
    $result =  StringCut::init()
	                 ->paragraph( false )  // 是否保持原段落,默认false
	                  ->endMark( '。' )  //整句判断标识,默认中文标点 ['。' , '?' , '!']
	                  ->length( 100 )//裁剪长度,默认120
	                  ->offset( 0.2 )//最大可偏移量,默认0.2(满足整句裁剪需求)
	                  ->get( '你的长字符串...' )
	                  ->toArray() );