fork download
  1. <?php
  2.  
  3. namespace /* global */ {
  4.  
  5. function test() {
  6. $images = [
  7. '37539' => 'some.png'
  8. ];
  9. $expr = '(?<=\\{\\[image:)\d+(?=]})';
  10. $text = '{[image:37539]}';
  11. preg_match_all("~{$expr}~", $text, $m);
  12. print_r($m);
  13.  
  14. $expr = '\\{\\[image:(\d+)]}';
  15. "~{$expr}~",
  16. function ($m) use($images) {
  17. return "<image src='{$images[$m[1]]}>'";
  18. },
  19. $text
  20. );
  21. var_dump($result);
  22. }
  23. test();
  24. }
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => 37539
        )

)
string(22) "<image src='some.png>'"