2
votes

I'm using the truncate method of the text helper and in doing so means any html included in the text is being rendered. Is there anyway to set the text helper to strip out html tags?

           echo $text->truncate(    
                $project['Project']['description'], 
                250,   
                array(
                    'ending' => '...', 
                    'exact' => false
                )
            );

Is there a modification to this similar to the stripLinks method?

thanks,

Jonesy

2

2 Answers

5
votes
echo $text->truncate(    
            $project['Project']['description'], 
            250,   
            array(
                'ending' => '...', 
                'exact' => false,
                'html' => true
            )
        );

that will make it respect the html structure. you can always use strip_tags(), there is nothing wrong with using php functions in cake :)

2
votes

Yes, you should use Sanitize::html($badString)
See the documentation.