0

I am trying to add the int with strings in PHP but I could get a helpful answer on StackOverflow and other website communities.

I want the code separate the ALPHABETS and NUMBER and then add the value in NUMBER and again JOIN the ALPHABETS AND ADDED NUMBER together.

How I achieve this, Please help.

Example:

$mynumber  = 'SBI0001';
$addValue = '1';

It will be 'SBI0002' in PHP.

4
  • Take a look at this post: stackoverflow.com/a/4538057/7993505 Commented Apr 6, 2021 at 6:41
  • Search for each part separately. Eg "php extract prefixed number" and "php format number with leading zeros" Commented Apr 6, 2021 at 6:42
  • @Richard it showing only number 1 but it should be 001 preg_match("/(\\d+)([0-9]+)/", "MFG001", $matches); $string = $matches[1]; $number = $matches[2]; echo $number; Commented Apr 6, 2021 at 6:49
  • @ShubhamNagar You can not add an int (1) to an string (001): Workflow: 1) find your number | 2) count the zeros e.g.: preg_match_all('/(0*)1/', $original_input, $output_array); | 3) rebuild your string = string+zeros*x+newValue Commented Apr 6, 2021 at 8:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.