Jim*_*988 1 php string str-replace
我究竟做错了什么?
$title = get_the_title();
$firstLetter = $title[0];
$title[0] = '<span class = "wrapBlue">' . $firstLetter . '</span>';
echo $title; // comes out with weird switched around string?
Run Code Online (Sandbox Code Playgroud)
get_the_title() 是一个wordpress功能.
var_dump on $title 给出一个长度为21的字符串.
var_dump on $firstLetter 给出一个包含长度为1的正确字符的字符串
如你所知,$title[0]是指第一个字母 - 但你要分配的不是一封信.尝试这样的事情:
$title = '<span class = "wrapBlue">' . $firstLetter . '</span>' . substr($title, 1);
Run Code Online (Sandbox Code Playgroud)