有谁知道如何在 PHP 中分解一些字符串,例如:
<?
// Submitted through register form
$first_name = $_POST['first_name'];
// example $_POST['first_name'] is somebody
// and need to be exploded at position 1 or by letter 'o' in this example
// but that is not always letter o
// I made also
$first_name_lc = strtolower($first_name);
// converted all to lowers and now
// exploding at letter o
$explode_rule = 'o';
$first_name_lc_exploded = explode($explode_rule, $first_name_lc);
// now in example we have $first_name_lc_exploded[0] and $first_name_lc_exploded[1]
// $first_name_lc_exploded[0] is now 's' and $first_name_lc_exploded[1] is 'mebody'
// now new first name is $first_name_lc_exploded[0].$explode_rule.$first_name_lc_exploded[1]
// but $first_name_lc_exploded[0] need to be converted in upper and only that, nothing else
// than $first_name_lc_exploded[0] is 'S' instead of 's'
// and first_name is now 'Somebody' instead of 'somebody'
?>
所以现在,问题是:如何用在字符串中查找第二个字母的东西替换字母 o,并用那个规则,一些变量来分解它。有人有想法吗?