how to remove new lines and returns from php string?

后端 未结 10 1063
孤城傲影
孤城傲影 2020-12-24 01:06

A php variable contains the following string:

text

text2

  • item1
  • item2
相关标签:
10条回答
  • 2020-12-24 01:57
    $no_newlines = str_replace("\r", '', str_replace("\n", '', $str_with_newlines));
    
    0 讨论(0)
  • 2020-12-24 01:57

    Replace a string :

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

    u using also like, (%n, %t, All Special characters, numbers, char,. etc)

    which means any thing u can replace in a string.

    0 讨论(0)
  • 2020-12-24 02:00

    To remove new lines from string, follow the below code

    $newstring = preg_replace("/[\n\r]/","",$subject); 
    
    0 讨论(0)
  • 2020-12-24 02:01

    you can pass an array of strings to str_replace, so you can do all in a single statement:

    $content = str_replace(["\r\n", "\n", "\r"], "", $content);
    
    0 讨论(0)
提交回复
热议问题