3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
41.48 ms | 402 KiB | 5 Q