nl2br() 將換行符轉(zhuǎn)HTML換行,\n轉(zhuǎn)<br>
nl2br() 接收二個參數(shù),第一個參數(shù)為需要轉(zhuǎn)換的字符串,第二個參數(shù)為是否為xhtml,
以下是 nl2br() 的語法:
nl2br(string, is_xhtml=True)
● string [str]:要處理的字符串。
● is_xhtml [bool]:是否為xhtml轉(zhuǎn)換。
返回一個字符串類型的數(shù)據(jù)
以下展示了使用 nl2br() 的實(shí)例:
from kyger.utility import nl2br print(nl2br('111\n222'))
以上實(shí)例運(yùn)行后輸出的結(jié)果為:
111<br />222