Função PHP para excluir tudo entre determinados caracteres em string

estou interessadofunction delete_all_between($char1, $char2, $string) que pesquisará dada $ string para $ char1 e $ char2 e, se tal for encontrado, limpar $ string da substring entre esses dois caracteres,Incluindo $ char1 e $ char2 em si.

Exemplo:

$string = 'Some valid and <script>some invalid</script> text!';
delete_all_between('<script>', '</script>', $string);

Agora, $ string deve conter apenas

'Some valid and  text'; //note two spaces between 'and  text'

Alguém tem solução rápida?

questionAnswers(5)

yourAnswerToTheQuestion