How can i edit this function to now show html tags?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php1016
Forum Newbie
Posts: 2
Joined: Wed Sep 16, 2009 9:24 am

How can i edit this function to now show html tags?

Post by php1016 »

Hello, im new to php programming and i want to know what the result would be if i removed "strip_tags" from line 4. What i would want to happen is that it would now show the html tags. Could someone show me the exact code that would allow me to now use html tags for the function on line 4? thank you, any help appreciated.

Code: Select all

// start mod: Product Captions (Short Descriptions)
// by Estelle (http://cubecart.expandingbrain.com)
if (!empty($productResults[$i]['short_description'])) {
 $view_cat->assign("TXT_DESC",strip_tags($productResults[$i]['short_description']));
} else {
 $view_cat->assign("TXT_DESC",substr(strip_tags($productResults[$i]['description']),0,$config['productPrecis'])."…");
}
// end mod: Product Captions (Short Descriptions)
 
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: How can i edit this function to now show html tags?

Post by Mirge »

User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: How can i edit this function to now show html tags?

Post by superdezign »

Because there is an inflexible call to substr(), removing strip_tags() gives you the possibility of breaking your content in the middle of a tag. This would cause something like this to happen:

If your raw data is:

Code: Select all

Our brand new product is <b>amazing!!</b>
If $config['productPrecis'] is 41, you would get:
Our brand new product is amazing!!
But if $config['productPrecis'] is 40, then you would get
Our brand new product is amazing!!</b
php1016
Forum Newbie
Posts: 2
Joined: Wed Sep 16, 2009 9:24 am

Re: How can i edit this function to now show html tags?

Post by php1016 »

Thanks for the replies.

Ive tested this by removing strip_tags from line 4 and it seems to work ok so far.

superdezign - I have not run into that yet. I will do some testing. thank you.
Post Reply