iamjonesy
iamjonesy

Reputation: 25132

CakePHP: Strip HTML using Text helper?

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

Upvotes: 2

Views: 4907

Answers (2)

dogmatic69
dogmatic69

Reputation: 7585

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 :)

Upvotes: 5

Adam
Adam

Reputation: 5070

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

Upvotes: 2

Related Questions