- preg_replace_callback: documentation ( source)
- preg_match: documentation ( source)
<?php
$html = "<div>
<img src='/logo.png'>[:ru]Привет мир[:en]Hello World[:]
</div>";
$lang = 'ru';
echo preg_replace_callback('#\[:.*\[:\]#isuU', function ($find) use ($lang) {
//print_r($matches);
if (preg_match('#\[:' + $lang + '\](.*)\[:#isuU', $find[0], $matches)) {
return $matches[1];
}
}, $html);