PHP-替换字符串出现 [英] php - replace string occurrences

查看:85
本文介绍了PHP-替换字符串出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串"First line | second line | third line" 如何用new line字符替换|?

I have a string "First line | second line | third line" How can I replace | with a new line character?

我正在尝试使用preg_replace,但是没有运气

I'm trying to use preg_replace but with no liuck

推荐答案

在这里

str_replace('|',"\n",$string);

将\ n放在双引号字符串中时,它将更改为新行

when \n is placed in double qouted string it changes to a new line

这篇关于PHP-替换字符串出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆