Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-06 20:16:56
Original
1150 people have browsed it

这篇文章主要介绍了php使用str_replace实现输入框回车替换br的方法,可实现使用\\n替换成br的方法,需要的朋友可以参考下

本文实例讲述了bs/php/2013092356327.html">php使用str_replace实现bs/javascript/2013080244832.html">输入框回车替换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程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!