user3162341
user3162341

Reputation: 251

Split two variables with the same string in starting of the variable name

I have the following :

$variable = bl45789;

The value bl will be always included in my variable.

How can I get only 45789.

With explode maybe ?

Upvotes: 0

Views: 41

Answers (2)

Alen
Alen

Reputation: 1788

$var = 'bl45789';
preg_match_all('!\d+!', $var, $result);
echo $result; // will display 45789

Upvotes: 1

hsz
hsz

Reputation: 152284

You can use substr

$variable = 'bl45789';
$output   =  substr($variable, 2);

Upvotes: 2

Related Questions