views:

27

answers:

2

Hi,

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

+1  A: 

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

Adam
correct me if i'm wrong but won't this just change html tags into text. so it will display the html tags but just not as html
iamjonesy
Using `'remove' => true` in the `$options` array removes the HTML tags.
Adam
+1  A: 
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 :)

dogmatic69
thanks, uised strip_tags() in the end
iamjonesy