PHP How to cut string without breaking any words or HTML tags
As title says I want to cut a string without breaking any words or HTML tags, now I found this function which sorts the html tags problem out *(slightly modified by myself)*

    function substrhtml($str,$start,$len){
    
    	$str_clean = substr(strip_tags($str),$start,$len);
    
    	if(preg_match_all('/\<[^>]+>/is',$str,$matches,PREG_OFFSET_CAPTURE)){
    
    		for($i=0;$i<count($matches[0]);$i++){
    
    			if($matches[0][$i][1] < $len){
    
    				$str_clean = substr($str_clean,0,$matches[0][$i][1]) . $matches[0][$i][0] . substr($str_clean,$matches[0][$i][1]);
    
    			}else if(preg_match('/\<[^>]+>$/is',$matches[0][$i][0])){
    
    				$str_clean = substr($str_clean,0,$matches[0][$i][1]) . $matches[0][$i][0] . substr($str_clean,$matches[0][$i][1]);
    
    				break;
    
    			}
    
    		}
    
    		return $str_clean;
    
    	}else{
    
    		return substr($str,$start,$len);
    
    	}
    
    }

[Source][1]

but it still cuts words in half mid sentence which I don't want to happen, any ideas on how to sort this?

As always any help is appreciated and thanks in advance.
  [1]: http://littlebearisland.com/entry113.html
PHP How to cut string without breaking any words or HTML tags
===

As title says I want to cut a string without breaking any words or HTML tags, now I found this function which sorts the html tags problem out *(slightly modified by myself)*

    function substrhtml($str,$start,$len){
    
    	$str_clean = substr(strip_tags($str),$start,$len);
    
    	if(preg_match_all('/\<[^>]+>/is',$str,$matches,PREG_OFFSET_CAPTURE)){
    
    		for($i=0;$i<count($matches[0]);$i++){
    
    			if($matches[0][$i][1] < $len){
    
    				$str_clean = substr($str_clean,0,$matches[0][$i][1]) . $matches[0][$i][0] . substr($str_clean,$matches[0][$i][1]);
    
    			}else if(preg_match('/\<[^>]+>$/is',$matches[0][$i][0])){
    
    				$str_clean = substr($str_clean,0,$matches[0][$i][1]) . $matches[0][$i][0] . substr($str_clean,$matches[0][$i][1]);
    
    				break;
    
    			}
    
    		}
    
    		return $str_clean;
    
    	}else{
    
    		return substr($str,$start,$len);
    
    	}
    
    }

[Source][1]

but it still cuts words in half mid sentence which I don't want to happen, any ideas on how to sort this?

As always any help is appreciated and thanks in advance.
  [1]: http://littlebearisland.com/entry113.html