- preg_replace: documentation ( source)
<?php
$names = array('joe123456',
'joe123',
'1joe1234',
'123joe456');
foreach ($names as $name) {
$new_name = preg_replace('/\d/', '', $name);
if (strlen($new_name) <= strlen($name) - 6) {
$name = $new_name;
}
echo "$name\n";
}