Ícone do site Linha de Comando

Como remover uma tag html e seu conteúdo com expressões regulares?

Tomando como base o texto abaixo, aprenda neste post, como remover a tag strong e seu conteúdo.

$string = "
Sexta, 13 de janeiro

Lorem Ipsum is simply dummy text of the printing and typesetting industry. "; echo preg_replace("~~Usi", "", $string);

Significado da opção Usi:
U non-greedy matching by default
s dot matches newline 
i case insensitive 

Resultado:


Lorem Ipsum is simply dummy text of the printing and typesetting industry.

Pra remover o br, basta usar a função nativa strip_tags().

Para testar Expressões Regulares online, clique aqui.

Sair da versão mobile