How to remove HTML tags from strings?

后端 未结 1 855
不知归路
不知归路 2021-01-28 15:21

I am looking to remove a chunk out of a string dynamically, from the occurrence of one character < to the occurrence of another set of 2 characters />

相关标签:
1条回答
  • 2021-01-28 16:16

    How about:

    $string = "<img src='blah.png' width="300" height="225" />There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slight...";
    $new_string = preg_replace('/<.*?\/>/','',$string);
    

    Still, if you're just parsing html tags, may regexp wouldn't be the best way to go. But if it's just removing some strings, then it may help.

    0 讨论(0)
提交回复
热议问题