How to remove only html tags in a string?

php, regex

Solution

Sorry I had not validate enough.

I have checked php5-cli expression below.

(?:<|&lt;)\/?([a-zA-Z]+) *[^<\/]*?(?:>|&gt;)

PHP code goes:

#!/usr/bin/php 
<?php

$str = "<html></html>
a<b 1<2 3>1 
<body>1>2</body>
<style file=\"'googe'\" alt=\"google\">hello world</style>
<have a good efghijknopqweryuip[]asdfgghjkzxcv bnm,.me>hello world<> google com</s>
<a se=\"font: googe;\">abcde</a>";

echo "text--->".preg_replace('/(?:<|&lt;)\/?([a-zA-Z]+) *[^<\/]*?(?:>|&gt;)/', '', $str)."\n";

?>

Result:

text--->
a<b 1<2 3>1 
1>2
hello world
hello world<> google com
abcde

Problem

I have written code for removing HTML tags, but it is also removing `a<b` type of strings. I want it to not to remove strings like `2<3` or `a<b`. ``` $term="a<b"; echo "Text is--->".preg_replace('/(?:<|&lt;).+?(?:>|&gt;)/', '', $term); ``` How do I remove html tags in a string, without removing LT or GT?

Original source

Related problems