<?php
$html = <<<HTML
<figure data-trix-attachment="{"content":"<span class=\"trix-token\" data-token-id=\"landlord_name\">Jméno pronajímatele</span>"}" 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;
$figureOpenTagPattern = \sprintf('<figure data-token-id="%s"[^>]*>','landlord_name');
$figureOpenTagReplacement = \sprintf('<figure data-token-id="%s">', 'landlord_name');
$figureEndTag = '<\/figure>';
$html = \preg_replace(
'/' . $figureOpenTagPattern . '(.+)' . $figureEndTag . '/U',
$figureOpenTagReplacement . \sprintf('<span class="trix-token %s %s" data-token-id="%s">%s</span>', 'landlord_name', 'tokenClass', 'landlord_name', 'test') . '</figure>',
$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="{"content":"<span class=\"trix-token\" data-token-id=\"landlord_name\">Jméno pronajímatele</span>"}" 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:
47.51 ms | 407 KiB | 5 Q