<?php
$s = "pa99";
$s++;
echo $s;
?>
The above code outputs to "pb00" What i wanted was "pa100" and so on.
But also in case its "pa", I want it to go to "pb" which works well with increment operator.
<?php
$s = "pa99";
$s++;
echo $s;
?>
The above code outputs to "pb00" What i wanted was "pa100" and so on.
But also in case its "pa", I want it to go to "pb" which works well with increment operator.
You are, as Michael says, trying to increment a string - it Does Not Work That Way (tm). What you want to do is this:
<?php
$s = "pa"; //we're defining the string separately!
$i = 99; //no quotes, this is a number
$i++;
echo $s.$i; //concatenate $i onto $s
?>
There's no automated way to increment a string (aa, ab, etc) the way you're asking. You could turn each letter into a number between 1-26 and increment them, and then increment the previous one on overflow. That's kind of messy, though.
To separate the integer from the string, try this:
From the docs:
PHP follows Perl's convention when dealing with arithmetic operations on character variables and not C's. For example, in PHP and Perl $a = 'Z'; $a++; turns $a into 'AA', while in C a = 'Z'; a++; turns a into '[' (ASCII value of 'Z' is 90, ASCII value of '[' is 91). Note that character variables can be incremented but not decremented and even so only plain ASCII characters (a-z and A-Z) are supported. Incrementing/decrementing other character variables has no effect, the original string is unchanged.