fork download
  1. <?php
  2.  
  3. $string = 'Hi I want @size suit which is @size-name';
  4.  
  5. $string = preg_replace_callback('~@(size-name|size)~', 'replace_sizes', $string);
  6.  
  7. print $string;
  8.  
  9. function replace_sizes($m) {
  10.  
  11. $size_text_array = array('size-name' => 'replaceword2', 'size' => 'replaceword');
  12.  
  13. return $size_text_array[$m[1]];
  14.  
  15. }
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Hi I want replaceword suit which is replaceword2