我想在第20个字符位置添加一个字符串(制作一个collapser)。
$link = '<span class="collapse"">'
$string = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam earum ex voluptate autem cupiditate tempora neque quis aliquam asperiores ab debitis nemo cumque, fuga quae, esse illum aut aliquid rem."
// Trying to add $link to $string at 20th character position
答案 0 :(得分:1)
使用substr_replace()
替换字符串
$link = '<span class="collapse"">';
$string = "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam earum ex voluptate autem cupiditate tempora neque quis aliquam asperiores ab debitis nemo cumque, fuga quae, esse illum aut aliquid rem.";
echo $newstr = substr_replace($string, $link, 20,0);
<强> DEMO 强>