zoukankan      html  css  js  c++  java
  • php str_replace 单引号 双引号 区别

    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"

  • 相关阅读:
    类和接口的区别
    ref 和out的区别
    重载 重写 多态区别
    UML种类与类的关系
    Window.open() 全攻略
    C#委托
    RT Diagnostics Routines
    tar.bz2 解压命令。
    教你10招最有效防电脑辐射方法
    预处理,编译, 优化, 汇编, 链接
  • 原文地址:https://www.cnblogs.com/zcy_soft/p/1934620.html
Copyright © 2011-2022 走看看