There is a line:

text_left {text_internal_figure_block} right_text

It is necessary to transform parts of a string using a regular part, not inside curly brackets, with a custom function, for example, you can use mb_strtoupper .

TEXT_LETTER {text_in_figured_box} TEXT_SPRAVA

  • Ways as always, a lot, for example, you can break the string as you need and perform the manipulation, then glue the string back. implode (), explode (). - Daniil
  • It is not particularly elegant. I would like to see a solution with the help of preg_replace_callback () - Dimas
  • Something like ([^{]+)(?>{)(?>[^}]+)(?>})(.*) - br3t

1 answer 1

 $str = "текст_слева{текст_внутри_фигурных_скобок}текст_справа" ; $newStr = preg_replace_callback( '/^[^{]+\{|\}[^}]+$/', function($matches) { return mb_strtoupper($matches[0]) ; }, $str ) ; // $newStr == "ТЕКСТ_СЛЕВА{текст_внутри_фигурных_скобок}ТЕКСТ_СПРАВА" 
  • Thank you And if we exclude the text_in the_figure_sbok and the curly brackets themselves? - Dimas
  • one
    @Dimas '/ ^ [^ {] + | [^}] + $ /' - Daniil
  • Thank! it's decided! - Dimas