i want to extract last four characters of the string how can

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lokesh_kumar_s
Forum Commoner
Posts: 48
Joined: Mon Apr 13, 2009 5:39 am
Contact:

i want to extract last four characters of the string how can

Post by lokesh_kumar_s »

i want to extract last four characters of the string how can i do it. and also i want to conver that last four chars to int and want to increment it by 1. how can i do it
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: i want to extract last four characters of the string how can

Post by Christopher »

There are several ways to do it. Here is one way:

Code: Select all

$new_number = intval(substr($string, -4)) + 1;
You probably don't need the intval() because PHP will convert to a number for the + operator.
(#10850)
Post Reply