This is easily possible with a regular expression and preg_match
:
preg_match('/affiliate_account_code_(\d+)/', $string, $matches);
\d+
matches an infinite (at least one) number of digits. The match between the parentheses can be retrieved using $matches[1]
.
Demo:
php> $string = 'affiliate_account_code_1';
'affiliate_account_code_1'
php> preg_match('/affiliate_account_code_(\d+)/', $string, $matches);
int(1)
php> $matches;
array (
0 => 'affiliate_account_code_1',
1 => '1',
)