我有一个类似这样的字符串:
This is line 1.* This is line 2.* This is line 3.
它的格式应该是这样的:
This is line 1.
This is line 2.
This is line 3.
我在想这必须使用substr()
或类似的东西来完成,但我不知道。
答案 0 :(得分:4)
您可以使用str_replace和nl2br功能。
<?php
$str = "This is line 1.* This is line 2.* This is line 3.";
echo nl2br(str_replace("*", "\n", $str));
?>
答案 1 :(得分:3)
这将为您完成:)
$s = "This is line 1.* This is line 2.* This is line 3.";
$d = implode("\n", explode('* ', $s));
返回此内容:
This is line 1.
This is line 2.
This is line 3.
或者,您可以使用str_replace()
执行此类操作:
$s = "This is line 1.* This is line 2.* This is line 3.";
$s = str_replace("* ", "\n", $s);
答案 2 :(得分:-1)
使用explode()函数拆分此字符串。