php - 如何替换字符串中的 \n?
问题描述
$data = $this->em->getRepository('App\\Entity\\Data')->findAll();
foreach ($data as $key => $value) {
$str1 = $value->getContent();
$str2 = "Line 1\nLine 2\rLine 3\r\nLine 4\n";
$order = array("\r\n", "\n", "\r");
$replace = '<br>';
$newstr1 = str_replace($order, $replace, $str1);
$newstr2 = str_replace($order, $replace, $str2);
}
$newstr2 的输出:
"Line 1<br>Line 2<br>Line 3<br>Line 4<br>"
$newstr1 的输出:
"Animals \n- 123 / N23\n- Monkeys together\n- 4 x 400ft. Farm rabits\n- 2 x 1000ft. Horses Cats\n- Group with all farm members\n- Flowers \n- Food\n- Love 400 -Random\r\n- 2-Countries\r\n- 1 x Hotel 4\"x4\"" \r\n- 1 x Shelter \r\n- Plate \r\n- Pillow \r\n- Cards"
我不明白,为什么\n
没有在 $newstr2 中替换
解决方案
推荐阅读
- java - Java 8 分组为对象集合
- java - ImagesService.applyTransform 上的间歇性 IllegalArgumentException
- css - CSS 可以创建多色梯形吗?
- sql - Always Encrypted 参数的默认值
- dart - Flutter:使用 navigator.dart 时断言失败
- c# - Identifier 为 Null 或为空,实体框架,更新数据库
- c# - 为什么在使用日期时使用 ToString()?
- c# - 使用密钥大小小于 2048 的 RSA 安全密钥创建 JWT 令牌时出错
- batch-file - 如何批量回显简短目录
- python - 熊猫数据框:在一个语句中识别 NaN 和零值