gpt4 book ai didi

php - 如何从字符串中转义新行

转载 作者:可可西里 更新时间:2023-10-31 22:40:15 25 4
gpt4 key购买 nike

是否有任何 php 方法可以从字符串中删除换行符?

$str ="
Hi
there
";

我的字符串在 'Hi' 和 'there' 之间包含一个换行符我希望输出为“你好”。我不想使用正则表达式。

最佳答案

这有点困惑

is there any php method to remove new line char from string?

看起来您确实希望将它们替换为空格。

$str = str_replace(array("\r\n", "\n", "\r"), ' ', $str);

假设替换是从左到右进行的,这应该适合 Windows 文本文件。

第一个分组是匹配同时使用\r 和\n 的 Windows 换行符。

关于php - 如何从字符串中转义新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3200087/

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