在每个 之后插入一个 <br> 。在数据库中的值

insert a <br> after each . in the value of the database

数据库中的值显示显示同段中的所有值。我想在我的回显代码中插入一个 <br>,这样任何 . (点)被检测到将意味着 <br>

下面是我的代码:

while($row = $result->fetch_assoc()) {

        echo "   ". $row["news"]. "<br>";

    }

您可以使用下面的代码片段。

$str = str_replace(".",".<br/>",$str);

它将用 .<br/>

替换每个点 (.)

str_replace — 用替换字符串替换所有出现的搜索字符串

语法:

str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) : mixed

在你的例子中,

while ($row = $result->fetch_assoc()) {
    $row["news"] = str_replace(".",".<br/>",$row["news"]);
}