我正在尝试创建一个pastebin类型的东西。 我已经得到了我的 php 代码
<?php
printf("uniqid(): %s\r\n", uniqid());
?>
<!DOCTYPE html>
<meta charset="UTF-8">
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Xdev - CodeShare</title>
</head>
<form method="post" action="cslink.php">
<textarea cols="100" rows="20" name="textbox"></textarea>
<br />
<input type="submit" value="Submit now" />
</form>
和我的 php 文件将其存储在我的 mysql 数据库中
<?php
require 'connect.php';
// Connecting to the MySQL database
$conn = mysql_connect($host, $user, $pass);
mysql_select_db($db);
$username = $_POST['textbox'];
$sql = "INSERT INTO `text` (`id`, `text` ) VALUES (NULL, '$username' );";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
?>
和我的 View 文件(也在 php 中)
<?php
require 'connect.php';
$sql = 'SELECT * FROM text WHERE id = 3';
$result = mysql_query($sql, $conn);
while ($row = mysql_fetch_assoc($result)){
$id = $row['id'];
$text = $row['text'];
echo "id: " . $id . "<br/>";
echo "text: " . $text . "<br/>";
echo $text;
}
?>
所以如果我输入:
hello
world
testing
(每个在单独的行上)
它将显示为:hello world测试
- 全部在一行中
我想知道是否可以以及如何将其作为单独的行输出
最佳答案
正如 @itachi 提到的,nl2br 应该可以解决这个问题。
关于php - 如何在浏览器上查看从Mysql DB获取的多行字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26593383/