in PHP, how to remove specific class from html tag?

后端 未结 4 918
忘了有多久
忘了有多久 2020-12-15 14:24

given the following string in PHP:

$html = \"

text 1

4条回答
  •  醉酒成梦
    2020-12-15 15:16

    You can use any DOM Parser, iterate over every element. Check whether its class attribute contains test2 class (strpos()) if so then set empty string as a value for class attribute.

    You can also use regular expressions to do that - much shorter way. Just find and replace (preg_replace()) using the following expression: #class=".*?test2.*?"#is

提交回复
热议问题