PHP form inserting
at the end of the text on each submission to MSSQL

后端 未结 1 1699
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 13:39

Hi everyone I had previously posted about a
getting inserted at the beginning of my text and we got that fixed. (here is my previous post with the code)

相关标签:
1条回答
  • 2021-01-26 14:09

    This should do it, matches <br>, <br/> or <br /> at the start or end:

    preg_replace('#^<br(\s*/)?>|<br(\s*/)?>$#i', "\n", $str);
    

    The tag is matched by: * Literal <br * Optional spaces followed by a forward slash

    The | in the middle is used to denote an alternative condition (i.e. OR).

    Edit

    Instead of <br(\s*/)?> you can also write <br(\/|)> that you had before.

    Edit 2

    Multiple occurrences can be matched by just adding + behind each pattern:

    preg_replace('#^<br(\/|)>+|<br(\/|)>+$#i', "\n", $str);
    
    0 讨论(0)
提交回复
热议问题