Home  >  Article  >  Backend Development  >  php使用str_replace实现输入框回车替换br的方法_PHP

php使用str_replace实现输入框回车替换br的方法_PHP

WBOY
WBOYOriginal
2016-05-31 19:27:13889browse

本文实例讲述了php使用str_replace实现输入框回车替换br的方法,分享给大家供大家参考。具体实现方法如下:

在我们用textarea时会发现回车与空格是不可看到的,所以我们利用str_replace函数将php中的\\n替换成br就可以了,有需要的朋友可以参考一下,代码如下:

代码如下:

function htmtocode($content) {
    $content = str_replace("n", "
", str_replace(" ", " ", $content));
    return $content;
}


先替换掉空格,再替换回车,相当于如下代码:

代码如下:

function htmtocode($content) {
    $content = str_replace(" ", " ", $content);
    $content = str_replace("n", "
",$content);   
    return $content;
}

希望本文所述对大家的PHP程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn