fork(2) download
  1. <?php
  2. $name = "abc";
  3.  
  4. $counter = 1;
  5. if($pos = strrpos($name, '_')) {
  6. $oldcounter = substr($name, $pos + 1);
  7. if(is_numeric($oldcounter)){
  8. $counter = $oldcounter + 1;
  9. $name = substr($name, 0, $pos);
  10. }
  11. }
  12.  
  13. $newname = $name . '_' . $counter;
  14.  
  15. print $newname;
  16. ?>
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
abc_1