How to remove only html tags in a string?

后端 未结 5 2223
庸人自扰
庸人自扰 2021-01-04 17:49

I have written code for removing HTML tags, but it is also removing a type of strings. I want it to not to remove strings like 2<3 or

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-04 18:23

    Sorry I had not validate enough.

    I have checked php5-cli expression below.

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

    PHP code goes:

    #!/usr/bin/php 
    
    a1 
    1>2
    
    hello world<> google com
    abcde";
    
    echo "text--->".preg_replace('/(?:<|<)\/?([a-zA-Z]+) *[^<\/]*?(?:>|>)/', '', $str)."\n";
    
    ?>
    

    Result:

    text--->
    a1 
    1>2
    hello world
    hello world<> google com
    abcde
    

提交回复
热议问题