fork download
  1. <?php
  2.  
  3. $str = '{c}
  4. <br>
  5. <br>
  6. test
  7. test<br>
  8. <br>{/c}
  9. <br>
  10. test
  11. test<br>
  12.  
  13. {c}
  14. saddasda<br>
  15. {/c}
  16.  
  17. {c}<br>test<br><br>{/c}
  18. {c}<br>{/c}';
  19. $new_str = preg_replace_callback('#(?<=\{c\}).*?(?=\{/c\})#s', function($matches) {
  20. return str_replace("<br>", "[linebreak]", $matches[0]);
  21. },$str);
  22. echo $new_str;
  23.  
Success #stdin #stdout 0.02s 23688KB
stdin
Standard input is empty
stdout
{c}
    [linebreak]
    [linebreak]
    test
    test[linebreak]
    [linebreak]{/c}
    <br>
    test
    test<br>
    
    {c}
    saddasda[linebreak]
    {/c}
    
    {c}[linebreak]test[linebreak][linebreak]{/c}
    {c}[linebreak]{/c}