Heim > php教程 > php手册 > php中表单输入框中换行回车替换

php中表单输入框中换行回车替换

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-13 09:56:31
Original
989 Leute haben es durchsucht

php中表单输入框中换行回车替换的一些方法总结,有需要的朋友可参考一下本文章。

 代码如下 复制代码


?$str="this is a test n";
$patten  = array("rn", "n", "r");  
?//先替换掉rn,然后是否存在n,最后替换r 
$str=str_replace($order, "", $str);
?>

 

?//php 有三种方法来解决  
 

 代码如下 复制代码

//1、使用str_replace 来替换换行 
$str = str_replace(array("rn", "r", "n"), "", $str); 
 
//2、使用正则替换 
$str = preg_replace('//s*/', '', $str); 
 
//3、使用php定义好的变量 (建议使用) 
$str = str_replace(PHP_EOL, '', $str);


?/*
* 获得用户操作系统的换行符,n
* @access public
* @return string
*/
function get_crlf()
{
    if (stristr($_SERVER['HTTP_USER_AGENT'], 'Win'))
    {
        $the_crlf = 'rn';
    }
    elseif (stristr($_SERVER['HTTP_USER_AGENT'], 'Mac'))
    {
        $the_crlf = 'r'; // for old MAC OS
    }
    else
    {
        $the_crlf = 'n';//权重大一点
    }
    return $the_crlf;
}

测试代码

 

 代码如下 复制代码




PHP获取表单area数据中的换行问题


$content=empty($_POST['content'])?null:trim($_POST['content']);
if(!empty($content))echo str_replace("r",'rl',nl2br($content));
echo "r".'
----------分割线----------------------'."r";
if(!empty($content))echo str_replace("n",'nl',nl2br($content));
echo "n".'
----------分割线----------------------'."n";
if(!empty($content))echo str_replace("r",'rl',str_replace("n",'nl',nl2br($content)));
echo "r".'
----------分割线----------------------
'."n";
echo 'hello'."n".'boys!';
echo 'hello'."r".'boys!';
?>








1.PHP函数nl2br()是在字符串中的每个新行(rn)之前插入HTML换行符:
;
2.Windows下的换行是(rn);
3.在记事本中,r或n均有换行的功能;

注意:在前台页面显示的时候,用nl2br使换行变成

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage