Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

php question string manipulation?

i've been playing with php for a month now

just need a li'l help :)

say i fetched a string in my table

$strStudID = $row['studid'];

returned: $strStudID = "DS-00099";

how can I increment that value to 1 so

that it would return "DS-00100"

i am really new to php and don't know

what functions to use to solve my problem

any help please?

Thans in Advance :)

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    //

    // The following code will work for any patterns

    // that end with number - for example,

    // XYZZ-1030303 - it will produce the string following

    // the same format

    $strStudID = "DS-00099";

    if (preg_match('/^(.*[^0-9])([0-9]+)$/', $strStudID, $parts)) {

    $prefix = $parts[1];

    $number = $parts[2];

    $length = strlen($number);

    $nextID = $prefix . sprintf("%0${length}d", $number+1);

    print "$nextID\n";

    } else {

    print "ID format was not recognized: $strStudID\n";

    }

  • oh! you need help from php expert

    Source(s): aadhunik
Still have questions? Get your answers by asking now.