[ create a new paste ] login | about

Link: http://codepad.org/6NBzpMtH    [ raw code | output | fork ]

PHP, pasted on Mar 13:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
$autoId = 11; /* this is the auto id from the database */
$id = "AZ2D20D7S99"; /* this is the user input */

/* find the trailing number and store it in $number */
preg_match("/[^\d]+(\d+)$/", $id, $matches);
$number = $matches[1];

/* increase the number by the database id */
$newNumber = $number + $autoId;

/* replace the old number with the new number */
echo preg_replace("/\d+$/", $newNumber, $id);
?>


Output:
1
2
3

Warning: preg_match(): Internal pcre_fullinfo() error -3 on line 6
AZ2D20D7S11


Create a new paste based on this one


Comments: