【发布时间】:2021-10-26 08:01:45
【问题描述】:
我正在尝试在给定字符串的第二个单词之后插入 <br/> 标签,但它会裁剪我的字符串中的一些单词,任何人都可以帮助修复此代码
$pos = 1;
$string = 'Lorem Imsem Dollar Country';
$words = explode(" ", $string);
$new_array = array_slice($words, 0, $pos, true) +
array($pos => '<br/>') +
array_slice($words, $pos, count($words) - 1, true) ;
$new_string = join(" ",$new_array);
echo $new_string;
【问题讨论】:
标签: php arrays string join slice