windows “\r\n" 或者 "\n"

linux "\n"

php 中 str_replace()函数的具体概况

str_replace($search, $replace, $subject)

例如

1

str_replace("\n", "<br/>", '465s4d6f5s4ad1as65d4fa6s\n54df65sdafgsdf\n65g4sd65g4hdf6\n54ghd6fbghdfgh'); //注意引号

输出:465s4d6f5s4ad1as65d4fa6s\n54df65sdafgsdf\n65g4sd65g4hdf6\n54ghd6fbghdfgh

2

 

str_replace("\n", "<br/>", "465s4d6f5s4ad1as65d4fa6s\n54df65sdafgsdf\n65g4sd65g4hdf6\n54ghd6fbghdfgh"); //注意引号

输出:

 465s4d6f5s4ad1as65d4fa6s

54df65sdafgsdf
65g4sd65g4hdf6
54ghd6fbghdfgh

3

str_replace('\n''<br/>'"465s4d6f5s4ad1as65d4fa6s\n54df65sdafgsdf\n65g4sd65g4hdf6\n54ghd6fbghdfgh"); //注意引号

输出:

465s4d6f5s4ad1as65d4fa6s 54df65sdafgsdf 65g4sd65g4hdf6 54ghd6fbghdfgh


注意:单引号只是表示纯粹的字符串

    而双引号是要经过编译器编译的

      也就是说在'\n'与"\n"有区别,前者是指字符串\n,而后者是经过编译器的\n,是转移字符的意思

      所以当只有$search和$subject变量同时为单引号或者双引号的时候才会有效果。

          从文本框或取出来的值都是转移的,也就是说存在着转移后的\n,所以用'\n'是没有用的,一定要用"\n"

 

相关文章:

  • 2021-06-27
  • 2021-11-02
  • 2021-11-06
  • 2022-01-14
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2021-07-09
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
相关资源
相似解决方案