3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <figure data-trix-attachment="{&quot;content&quot;:&quot;<span class=\&quot;trix-token\&quot; data-token-id=\&quot;landlord_name\&quot;>Jméno pronajímatele</span>&quot;}" data-trix-content-type="undefined" class="attachment attachment--content"><span class="trix-token">Jméno pronajímatele</span><figcaption class="attachment__caption"></figcaption></figure> HTML; $tokenId = 'landlord_name'; $figurePattern = '/<figure([^>]*)data-token-id="' . $tokenId . '"[^>]*>(.*?)<\/figure>/s'; $replacement = '<figure$1 data-token-id="' . $tokenId . '"><span class="trix-token ' . $tokenId . ' tokenClass" data-token-id="' . $tokenId . '">test</span></figure>'; // Provedeme nahrazení $html = \preg_replace($figurePattern, $replacement, $html); echo $html;
Output for 8.2.0 - 8.2.28, 8.3.0 - 8.3.22, 8.4.1 - 8.4.8
<figure data-trix-attachment="{&quot;content&quot;:&quot;<span class=\&quot;trix-token\&quot; data-token-id=\&quot;landlord_name\&quot;>Jméno pronajímatele</span>&quot;}" data-trix-content-type="undefined" class="attachment attachment--content"><span class="trix-token">Jméno pronajímatele</span><figcaption class="attachment__caption"></figcaption></figure>

preferences:
48.26 ms | 407 KiB | 5 Q