Reputation: 4264
I am trying to instert an integer into a form. Users are asked to input there promo number which is in the format 12.2-9999. I only want to insert 9999 into the column in my database but I am getting -9999 in the columns. I am not sure if I should use preg_replace or something else here?
Upvotes: 0
Views: 140
Reputation: 59699
Just use explode()
, like so:
list( , $promo) = explode( '-', '12.2-9999');
Now $promo
will contain 9999
.
Upvotes: 4
Reputation: 74202
The following regular expression will check for the last -
and capture the digits to the end (which as per the example is 9999
):
/-(\d+)$/
Upvotes: 2