Python's equivalent to PHP's strip_tags?
+6
A:
There is no such thing in the Python standard library. It's because Python is a general purpose language while PHP started as a Web oriented language.
Nevertheless, you have 3 solutions:
- You are in a hurry: just make your own.
re.sub(r'<[^>]*?>', '', value)
can be a quick and dirty solution. - Use a third party library (recommended because more bullet proof) : beautiful soup is a really good one and there is nothing to install, just copy the lib dir and import. Full tuto with beautiful soup.
- Use a framework. Most Web Python devs never code from scratch, they use a framework such as django that does automatically this stuff for you. Full tuto with django.
e-satis
2010-02-19 11:40:07
Hey! I'm using Django =)
Viet
2010-02-19 11:52:32
+1
A:
Python doesn't have one built-in, but there are an ungodly number of implementations.
Ignacio Vazquez-Abrams
2010-02-19 11:40:58
Actually I Googled with the same query you suggested but those didn't make me happy enough.
Viet
2010-02-19 11:55:10
+6
A:
Using BeautifulSoup
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(htmltext)
''.join([e for e in soup.recursiveChildGenerator() if isinstance(e,unicode)])
gnibbler
2010-02-19 11:41:48
+1
A:
You won't find many builtin Python equivalents for builtin PHP HTML functions since Python is more of a general-purpose scripting language than a web development language. For HTML processing, BeautifulSoup is generally recommended.
Otto Allmendinger
2010-02-19 11:44:28