Sunday, 15 February 2015

php - Separate number following underscore off end of string? Regex? -



php - Separate number following underscore off end of string? Regex? -

i'm ob-c programmer needs php current project. i'm guessing need utilize regex current problem, have never used regex , has proven lot bite off in 1 go, single problem. similar questions have found on haven't helped me solve problem written people fair thought of how this, , said, total newbie in area.

my problem this:

i have string, ends underscore followed number:

$string = xxxxxxxx_123

i want separate 2 strings:

$root = xxxxxxxx_ and $number = 123

things more complicated in that:

the xxxxxx contain other underscores or digits (e.g.. total thing xx_x12_9_123, in case want separate xx_x12_9_ , 123. (the underscore want divided after lastly underscore.) the number @ end number of digits long (although minimum of 1)

(in case haven't guessed, these file names need incremented)

thanks time

$pos = strrpos($string, '_') + 1; $root = substr($string, 0, $pos); $number = substr($string, $pos);

php regex

No comments:

Post a Comment