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);
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in /in/es0JC on line 33 <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&amp;format=json&amp;maxwidth=500&amp;width=1" data-oembed-id="B5mtrL3p3XV" data-oembed-options="{&quot;maxwidth&quot;:&quot;500&quot;,&quot;width&quot;:true}"> <figure class="moki-embed-instagram"> <img src="https://instagram.com/p/B5mtrL3p3XV/media/?size=l"/> <figcaption> <i class="fa fa-instagram icon"/> </figcaption> </figure> @CHANGE@がある </div> <br/>a </span> V... </div> </div>
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33
<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&amp;format=json&amp;maxwidth=500&amp;width=1" data-oembed-id="B5mtrL3p3XV" data-oembed-options="{&quot;maxwidth&quot;:&quot;500&quot;,&quot;width&quot;:true}"> <figure class="moki-embed-instagram"> <img src="https://instagram.com/p/B5mtrL3p3XV/media/?size=l"/> <figcaption> <i class="fa fa-instagram icon"/> </figcaption> </figure> @CHANGE@がある </div> <br/>a </span> V... </div> </div>

preferences:
173.82 ms | 413 KiB | 5 Q