fork download
  1. <?php
  2. $input = '@Hello@ & Good Day ~World~';
  3. echo preg_replace_callback('/([@~])(.*?)([@~])/im', function ($matches){
  4. return (strpos($matches[1], '@') !== false) ? "<i>{$matches[2]}</i>" : "<b>{$matches[2]}</b>";}, $input);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
<i>Hello</i> & Good Day <b>World</b>