3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <div> Vがある<br> <div id="body-top" class="content-moki clearfix"> Vがある<br> <span class="headline"> <br> にモデル「V」を入れると、プレビューでエンベットが崩れる<br> <br> <div class="oembed oembed-type-instagram" data-oembed-medialink="https://www.instagram.com/p/B5mtrL3p3XV/" style="margin:10px auto;max-width: 500px;" data-oembed-url="https://api.instagram.com/oembed/?url=https%3A%2F%2Fwww.instagram.com%2Fp%2FB5mtrL3p3XV&format=json&maxwidth=500&width=1" data-oembed-id="B5mtrL3p3XV" data-oembed-options='{"maxwidth":"500","width":true}'> <figure class="moki-embed-instagram"> <img src="https://instagram.com/p/B5mtrL3p3XV/media/?size=l"> <figcaption> <i class="fa fa-instagram icon"></i> </figcaption> </figure> Vがある </div> <br>a </span> V... </div> </div> HTML; $needle = 'V'; $replace = '@CHANGE@'; libxml_use_internal_errors(true); $dom = new DOMDocument('1.0', 'utf-8'); $dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($dom); foreach ($xpath->query("//div[contains(@class, 'oembed')]/text()[contains(.,'$needle')]") as $node) { $node->nodeValue = str_replace($needle, $replace, $node->nodeValue); } echo $dom->saveXML($dom->documentElement);

preferences:
30.48 ms | 410 KiB | 6 Q