fork(1) download
  1. <?php
  2.  
  3. $string = "user is ?user_id=34&first_name=Ralph so is ?user_id=1 also";
  4. $result = preg_replace('/\?(user)_id=(\d+)(.*?)(?! )/i', '/$1/$2/$3', $string );
  5.  
  6. echo $result ;
Success #stdin #stdout 0.02s 24192KB
stdin
Standard input is empty
stdout
user is /user/34/&first_name=Ralph so is /user/1/ also