fork(1) download
  1. <?php
  2.  
  3. $string1 = "This is a test XYZ something else";
  4. $string2 = "This is a test? XYZ something else";
  5. $pattern = " XYZ";
  6. echo preg_replace_callback('~\B'.$pattern.'~', function($m) { return trim($m[0]); }, $string1) . PHP_EOL;
  7. echo preg_replace_callback('~\B'.$pattern.'~', function($m) { return trim($m[0]); }, $string2);
Success #stdin #stdout 0.03s 52432KB
stdin
Standard input is empty
stdout
This is a test XYZ something else
This is a test?XYZ something else