You are here: How to strip styles embedded within html tags? « PHP Programming Language « IT news, forums, messages
How to strip styles embedded within html tags?

Posted by Steve on 10/18/06 10:17

Hi,
I'm a complete PHP n00b slowly finding my way around
I'm using the following function that I found on php.net to strip
out html and return only the text. It works well except for when
you find styles embedded within the tags
eg: <h3 id="pageName">Have a great day!! </h3>
This throws an error, whereas
<h3 >Thank you for your purchase! </h3> works like a charm.
It also falls over when crappy code has <h3>&nbsp;</h3> between
the tags.

What do I need to add to the below function to get it to work on
cases like above?
regards,
Steve

The function is:

function html2txt($txt){
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out
javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out
HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style
tags properly
'@<![\s\S]*?--[ \t\n\r]*>@', // Strip
multi-line comments including CDATA
"@</?[^>]*>*@"


);
$text = preg_replace($search, '', $txt);
return $text;
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация