Html substr

I found the following function on internet to html crop.
It is almost working well…


print html_substr("<p>my </p><p><a href='http://www.google.com''>markeup</a></p> <p><b>text</b></p>", 0, 5 ); // <p>my </p><p><a href='http://www.google.com''>ma</a> <p><b></b></p>

How can I remove all <p><b></b></p> tags?
Basically after the limit, it is showing all tags without text.
It should not be appearing…

Thanks


print html_substr("<p>my </p><p><a href='http://www.google.com''>markeup</a></p> <p><b>text</b></p>", 0, 5 );


function html_substr( $s, $srt, $len = NULL, $strict=false, $suffix = NULL )
{
	if ( is_null($len) ){ $len = strlen( $s ); }
	
	$f = 'static $strlen=0; 
			if ( $strlen >= ' . $len . ' ) { return "><"; } 
			$html_str = html_entity_decode( $a[1] );
			$subsrt   = max(0, ('.$srt.'-$strlen));
			$sublen = ' . ( empty($strict)? '(' . $len . '-$strlen)' : 'max(@strpos( $html_str, "' . ($strict===2?'.':' ') . '", (' . $len . ' - $strlen + $subsrt - 1 )), ' . $len . ' - $strlen)' ) . ';
			$new_str = substr( $html_str, $subsrt,$sublen); 
			$strlen += $new_str_len = strlen( $new_str );
			$suffix = ' . (!empty( $suffix ) ? '($new_str_len===$sublen?"'.$suffix.'":"")' : '""' ) . ';
			return ">" . htmlentities($new_str, ENT_QUOTES, "UTF-8") . "$suffix<";';
	
	return preg_replace( array( "#<[^/][^>]+>(?R)*</[^>]+>#", "#(<(b|h)r\\s?/?>){2,}$#is"), "", trim( rtrim( ltrim( preg_replace_callback( "#>([^<]+)<#", create_function(
            '$a',
          $f
        ), ">$s<"  ), ">"), "<" ) ) );
}
die();

See strip_tags once.

Hi Rajug,

Only want to strip tags after the limit, before the limit function is working ok.

Any ideas? Seems not be easy to remove all tags only after the crop limit…