将多个字符串组合成一个textarea

时间:2013-05-26 17:58:14

标签: php string textarea

有人可以告诉我如何在一个textarea下创建此代码。我对php很新,所以任何建议都会有所帮助,谢谢。

if ($test != "")
  print("<p>" . format_comment($test) . "</p>\n");
if ($test1 != "")
  print("<p>" . format_comment($test1) . "</p>\n");

干杯。

2 个答案:

答案 0 :(得分:0)

这很容易实现,请尝试这样:

// Print the top
print("<p><hr>");

// Print $text if set
if ($test != "")
  print(format_comment($test));

// Print $text1 if set
if ($test1 != "")
  print(format_comment($test1));

// Print the bottom
print("<hr></p><br />");

尽管如此,我建议您使用echo代替print,因为echo是一种更常用的功能。使用echo,您可以这样做:

echo "<p><hr>";
if ($test != "")
  echo format_comment($test);
if ($test1 != "")
  echo format_comment($test1);
echo "<hr></p><br />";

我可能理解你的问题是错误的,如果你只是想把变量中的内容放到文本区域,你可以按如下方式进行:

$content = "";
if ($test != "")
  $content .= "<p><hr>" . format_comment($test) . "<hr></p><br />";
if ($test1 != "")
  $content .= "<p><hr>" . format_comment($test1) . "<hr></p><br />";
echo "<textarea>" . $content . "</textarea>";

编辑:看起来您已使用\n来获取新行,您应该在HTML中使用<br />。只需用\n替换所有<br />部分即可解决问题。

希望这有帮助!

答案 1 :(得分:0)

您可以尝试连接两个内容

<?php
require "include/bittorrent.php";
dbconn(); 


stdhead("Tags");
begin_main_frame();
begin_frame("Tags");
$test = $_POST["test"];
$test1 = $_POST["test1"];

    $content="<p><hr>";

    if ($test != "")
      $content .= format_comment($test);
    if ($test1 != "")
      $content .= format_comment($test1);

    $content=$content. "<hr></p><br />";
?>

 <textarea id="test" name="test"><?php echo $content; ?></textarea>


<?php 

end_frame();
end_main_frame();
stdfoot();
?>