Remove tags from a string and then remove whitespace

There are many times when we need to create a product feed etc that doesn’t contain any html tags in the new string. strip_tags can clear out the tags but leaves your string unreadable in many instances.

Here’s a quick way to remove any tag and then remove the whitespace that remains so that your text in the string is readable.

If you only want a specific tag, just change the data inside the brackets.

By replacing the tag with a space first, you’re able to go back and only change instances where double-spaces remain, keeping your string readable. Some instances of replacing tags you want a space replacement, while others you want to remove the space completely.

Magento Tips & Techniques

Magento is one of the leading E-Commerce platforms. The information provided in this site hopefully will help you with some "tweaks" to enhance the shopping experience or assist the administrator.

The posts are in no particular order but are added whenever I think of a tip, technique, code snippet or change that I think might be useful to the community.

I've only included 'hacks' that can be implemented by someone with a general Magento structure knowledge and basic php skills. More sophisticated Magento modifications are available from numerous sites and the Magento Knowledge base.