2

我有一个 textarea 值,它的值来自一个字段(nl2br)

如何去掉“<br/>”,这样当我想编辑这个字段时,“<br/>”就不会出现了?

//$data["Content"] is the field that has <br/> tags inside
$content = $data["Content"];

//when want to edit, want to strip the <br/> tag
<td><textarea name="content" rows="10" style="width:300px;"><?=$content?></textarea></td>

我知道它应该使用 strip_tags() 函数,但不确定真正的方法

任何帮助,将不胜感激

4

2 回答 2

4

如果你想使用 strip_tags,那么它就是:

$content = strip_tags($data["Content"]);
于 2011-05-29T12:11:53.367 回答
2

我将使用str_replace以下将替换<br/>为换行符

$content = str_replace('<br/>','\n',$data['Content']);

或者如果你不想要换行符

$content = str_replace('<br/>','',$data['Content']);

编辑 一个例子

$my_br = 'hello<br/> world';
$content = str_replace('<br/>','',$my_br);

echo $content;

Output: hello world
于 2011-05-29T12:12:24.493 回答