gpt4 book ai didi

php - 如何在分解字符串之前和之后添加文本

转载 作者:行者123 更新时间:2023-11-30 00:39:23 24 4
gpt4 key购买 nike

嗨,我正在从 MySQL 获取一些数据

    <ol>
<li></li>
<li></li>
<li></li>
</ol>
explode('<li>', $data );

我将 <li> 之后的字符串分解现在我想在第一个数组之前和最后一个数组之后添加某些值如何实现

当前结果是

 hi

hi1

hi2

我想要像这样的结果

  • 嗨*
  • 嗨1 *
  • 嗨2*

最佳答案

请按照以下代码操作:

$str = 'hi
hi1
hi2';
$array = explode(' ', $str);
foreach ($array as $arr)
{
echo "<li>$arr *</li>";
}

关于php - 如何在分解字符串之前和之后添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21899502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com