【问题标题】:combine multiple strings into one textarea将多个字符串组合成一个文本区域
【发布时间】:2013-05-26 17:58:13
【问题描述】:

谁能告诉我如何在一个文本区域下制作这段代码。我对 php 还很陌生,所以任何一点建议都会有所帮助,谢谢。

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

干杯。

【问题讨论】:

  • “制作此代码”和“在一个文本区域下”是什么意思? print("&lt;textarea&gt;$test\n$test1&lt;/textarea&gt;"); 之类的东西?

标签: php string textarea


【解决方案1】:

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

// 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 中使用&lt;br /&gt;。只需将所有 \nparts 替换为 &lt;br /&gt; 即可解决问题。

希望这会有所帮助!

【讨论】:

  • 感谢您的帮助。您提供的第一个代码有效,但两个 $test 和 $test1 最终在一行中。是否有可能做到这一点,这样他们就可以最终一个在另一个之下?
  • 是的,我认为您已经使用\n 获得了一个新行,您应该使用&lt;br /&gt;,因此只需将那些\n 部分替换为&lt;br /&gt;,仅此而已。我很高兴它有效!
  • 你能告诉我在哪里可以放
    代码吗?因为我得到了很多错误......
  • 在文本区域我得到这个:


    $test


    test1

  • 从技术上讲,我有 2 个文件 temp.php 和 formm.php。当我在 websitename.com/temp.php 中输入内容时,我希望将其发送到 textarea 框中的 websitename.com/formm.php。野兔是两者的粘贴箱:pastebin.com/kBMA5MA9pastebin.com/PP66dnaL
【解决方案2】:

您可以尝试连接两个内容

<?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();
?>

【讨论】:

  • 抱歉回复我是这个网站的新手xD
  • 我在编辑时没有看到你在做什么..让我看看..你不需要打印来创建它..你可以尝试我制作的方式..如果您的问题由此解决,那么您可以选择它作为正确的答案:)
  • 它给了我解析错误:解析错误,第 2 行出现意外 '
  • @nidal khalaf 我添加了
    你可以检查一下。
  • 第 2 行仍有意外的 'pastebin.com/PP66dnaL
猜你喜欢
  • 2021-08-12
  • 2018-10-01
  • 1970-01-01
  • 2013-12-25
  • 1970-01-01
  • 1970-01-01
  • 2019-03-22
  • 1970-01-01
  • 2011-04-30
相关资源
最近更新 更多