- ltrim: documentation ( source)
- preg_match: documentation ( source)
- json_encode: documentation ( source)
<?php
$strings = [
'my_name_is_John_Doe',
'my_name_is john doe',
'my_name_is_john_doe',
'i_am_20_years_old',
"i'm_cool!"
];
foreach ($strings as $string) {
echo json_encode([
$string,
!strlen(ltrim($string, 'a..z_')),
!preg_match('/[a-z_]*[^a-z_]/', $string)
]);
echo "\n\n";
}