Created
April 30, 2019 08:00
-
-
Save Jason-cqtan/c6c4d9fdaeec10708f3463a660f4b4e7 to your computer and use it in GitHub Desktop.
textarea内容空格换行处理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* textarea文本内容空白、换行替换html实体标签 | |
* @param $sContent | |
* @return string|string[]|null | |
*/ | |
function textToHtml($sContent) | |
{ | |
$pattern = array( | |
'/ /',//半角下空格 | |
'/ /',//全角下空格 | |
'/\r\n/',//window 下换行符 | |
'/\n/',//Linux && Unix 下换行符 | |
); | |
$replace = array(' ',' ','<br/>','<br/>'); | |
return preg_replace($pattern, $replace, $sContent); | |
} | |
/** | |
* HTML实体标签转textarea内部显示标签 | |
* @param $sContent | |
* @return string|string[]|null | |
*/ | |
function htmlToText($sContent) | |
{ | |
$pattern = array("/ /","/ /","/\<br\/>/","/\<br\/>/"); | |
$replace = array( | |
' ',//半角下空格 | |
' ',//全角下空格 | |
"\r\n",//window 下换行符 | |
"\n",//Linux && Unix 下换行符 | |
); | |
return preg_replace($pattern, $replace, $sContent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment