functioncapitalizeFirstLetter($str){if(strlen($str) >0) {$str[0] =strtoupper($str[0]); }return$str; }$str="hello world";echocapitalizeFirstLetter($str);// 输出: Hello world AI代码助手复制代码 注意事项 自定义函数可以根据具体需求进行扩展和优化。 这种方法适用于需要特殊处理的场景,但通常不...
$str = strtolower(trim($string)); // Capitalize all first letters $str = preg_replace_callback('/\\b(\\w)/', function ($m) { return strtoupper($m[1]); }, $str); if ($all_uppercase) { // Capitalize acronyms and initialisms (e.g. PHP) $str = preg_replace_callback('/\\...
To make the first letter of a PHP string uppercase and the rest lowercase, you can do the following: Make string lowercase (using strtolower()); Capitalize only the first letter (using u
return $string; } ?> Hope it helps someone.Alex (27-Aug-2008 05:43) A modified sentenceNormalizer by gregomm Features: 1- Removes duplicated question marks, exclamations and periods 2- Capitalize first letter of a sentence. 3- Split sentences not only with "." but also with "?" and...
return $string; } ?> Svetoslav Marinov http://slavi.bizup down 1 bgschool ¶ 15 years ago Simple function for use ucfirst with utf-8 encoded cyrylic text <?php public function capitalize_first($str) { $line = iconv("UTF-8", "Windows-1251", $str); // convert to windows-...
$str = strtolower(trim($string)); // Capitalize all first letters $str = preg_replace_callback('/\\b(\\w)/', function ($m) { return strtoupper($m[1]); }, $str); if ($all_uppercase) { // Capitalize acronyms and initialisms (e.g. PHP) $str = preg_replace_callback('/\\...
my_ucfirst(strtolower(trim($sentence))) : $sentence.' '; } return trim($new_string); } ?> bgschool (30-Jul-2009 12:39) Simple function for use ucfirst with utf-8 encoded cyrylic text <?php public function capitalize_first($str) { $line = iconv("UTF-8", "Windows-1251", $str...
::first-letter设置对象内的第一个字符的样式。 ::first-line设置对象内的第一行的样式。 :before设置在对象前(依据对象树的逻辑结构)发生的内容。 :after设置在对象后(依据对象树的逻辑结构)发生的内容。 :lang(language)匹配使用特殊语言的E元素。
Use this to capitalize first letter of all array keys:<?phpfunction ucfirstKeys(&$data){ foreach ($data as $key => $value) {// Convert key$newKey = ucfirst($key);// Change key if neededif ($newKey != $key) { unset($data[$key]);$data[$newKey] = $value; }// Handle nest...
2- Capitalize first letter of a sentence. 3- Split sentences not only with "." but also with "?" and "!" 4- Puts a white space at the end of each sentence 5- Retains newlines --removed from orginal function-- undestand the meaning of "?" and "?" in languages like spanish. unde...