php - 将 <br/> 转换为用于文本区域的新行

标签 php html

如果我有一个变量:

$var1 = "Line 1 info blah blah <br /> Line 2 info blah blah";

还有一个文本区域:

<textarea>echo $var1</textarea>

如何让文本区域显示一个新行而不是像使用 <br /> 那样在单个文本区域显示文本?在里面?

编辑:我尝试了以下方法:

<textarea class="hobbieTalk" id="hobbieTalk" name="hobbieTalk" cols="35" rows="5" onchange="contentHandler('userInterests',this.id,this.value,0)"><?php

$convert=$_SESSION["hobbieTalk"];
$convert = str_replace("<br />", "\n", $convert);
echo $convert;

?></textarea>

但是文本区域仍然包含 br行中的标签。

最佳答案

试试这个

<?php
    $text = "Hello <br /> Hello again <br> Hello again again <br/> Goodbye <BR>";
    $breaks = array("<br />","<br>","<br/>");  
    $text = str_ireplace($breaks, "\r\n", $text);  
?>  
<textarea><?php echo $text; ?></textarea>

关于php - 将 <br/> 转换为用于文本区域的新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6004343/

相关文章:

javascript - jquery变量没有被发送

php - div 没有做它应该做的事

php - 我的 PHP 引用数组是 "magically"成为一个值数组......为什么?

html - 删除 overflow-auto div 下的空白

html - CSS - 使用 Bootstrap 从行和列中删除所有宽度

jquery - 使用 .animate() jquery 制作动画

php - 将 "//"注释与正则表达式匹配但不在引号内

javascript - 在网页上使用 Annotorious 时遇到的问题

javascript - 如何从文本区域输入创建 $_POST 数组

javascript - 我无法在页面加载时加载放大的弹出窗口