Removing all numbers


$myVar='xy12 d2_6 dkr';

$myvar=$str_replace('0','', $myVar);
$myvar=$str_replace('1','', $myVar);
$myvar=$str_replace('2','', $myVar);
$myvar=$str_replace('3','', $myVar);
$myvar=$str_replace('4','', $myVar);
$myvar=$str_replace('5','', $myVar);
$myvar=$str_replace('6','', $myVar);
$myvar=$str_replace('7','', $myVar);
$myvar=$str_replace('8','', $myVar);
$myvar=$str_replace('9','', $myVar);

echo $myVar;


xy d_ dkr

The code above removes all numbers of the variable ‘$myVar’,
I guess there may be better code for it.
Do you have any?
Maybe regular expression…

Yep, a regular expression would be easier

$myVar = preg_replace('/[0-9]+/', '', $myVar);

[COLOR=#000000][COLOR=#0000BB]Or slightly shorter:

$myVar [/COLOR]= preg_replace(‘/\d+/’, ‘’, $myVar);[/COLOR]

For some reason I thought \d would remove + and - signs so I didn’t use it, but I guess it doesn’t, so yes, that is a good alternative too.