J'ai ce HTML
$string = preg_replace("/<h1>[^>]+>/","", $string); //remove <h1>
$string = preg_replace('|\<h1.*\>(.*\n*)\</h1\>|isU', '', $string);
3 Réponses :
avec php strong> Vous pouvez également utiliser str_replace strong>.
Essayez cette regex -
$string = preg_replace("/\<h1(.*)\>(.*)\<\/h1\>/","", $string); //remove <h1>
En fait, cela ne fonctionne pas, j'ai apporté des modifications à mon post
Check - Sandbox.onlinephPFonctions.com/code/...
Vous pouvez essayer cela.
$htmlStr="<div>
<h1>Welcome</h1>
It is sunny outside.....
</div>";
$htmlStr = preg_replace('/<h1>.*<\/h1>/',' ', $htmlStr);
echo $htmlStr;
Vous pouvez le tromper à l'aide de JavaScript
La structure est-elle toujours aussi simple? Pourquoi ne pas utiliser un analyseur DOM?
Si vous êtes sûr à 100% qu'il ressemble toujours à cela (pas de classes sur le H1, etc.), cela devrait alors fonctionner:
/ (. * <\ / H1>) / i code>. Voici une démo
J'ai fait des modifications, il y a iParprop et style