为了优化网站的发布,这里需要自动将\n等换行符自动转换为p标签,下面方法可以分享给大家使用。
/**
* 将换行符号转换为p标签
* @param $str 待转换的字符串
*/
function phpeolToHtml($str){
$tempInfo = $str;
$tempInfo = explode(PHP_EOL,$tempInfo);
$tempStr = '';
foreach ($tempInfo as $tempKey => $tempValue){
$tempStr .= '<p>'.$tempValue.'</p>';
}
return $tempStr;
}