Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串,我nl2br用来插入换行符。
nl2br
我怎样才能让它只在所有换行符之前插入一个换行符而不是在所有新行之前插入一个换行符
之后您可以使用 preg_replace() 匹配所有重复的 BR 并替换为单个
$pattern = "/(\<br\/\>)+/i"; $replacement = "<br/>"; $subject = "hi<br/><br/><br/>how are<br/>you"; $limit = -1; $count = 0; $result = preg_replace ($pattern, $replacement, $subject, $limit, $count);