在显示文本方面的内容时,如何使线路断裂?

发布于 2025-02-04 18:51:02 字数 598 浏览 3 评论 0 原文

我正在尝试在PHP中进行论坛。 我有问题。我有一个带有文本方面的发布表格。想像一下我填补了这一切。

当我在数据库中使用NL2BR时,将换行线路(按Space Bar)时,添加了< br> 标签。但是,当我只输入并且存在自动折线时,就没有< br>

我该怎么做,例如,在100个字符的末期,有一个自动线路休息(在数据库中添加了< br> 。我已经在JavaScript中尝试过 答案。

't找到

了正确的

在数据库中

没有

​png“ rel =”数据库中的nofollow noreferrer>

问题:

I'm trying to do a forum in php.
I have a problem. I have a publish form with a textarea. Let's imagine that I fill it all.

When I make a line break (when I press space bar), with nl2br, in my database there are <br> tags added. But when I just type and there is an auto line break, there is no <br>.

How can I do to, for example, at the end of 100 chars, there is an auto line break (that adds a <br> in the database. I've tried in Javascript but I didn't found a correct answer.

With

with <br>

In the database

Without

auto line break in textarea (no <br>)

in the database

Problem:

in the forum (text outside of the div

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南街女流氓 2025-02-11 18:51:02

关于PHP的第一部分,我现在还创建了PHP网站,但它是社交媒体,在这里我如何进行销售线路,并逃避”或> \ 之类的字符我的聊天

$letter = join("", explode("\r\n", $letter));
$letter = join(" \\\\ ", explode("\\", $letter));
$letter = join("\\\"", explode("\"", $letter));
$stmt = $mysqli->prepare("INSERT INTO Chat (sender, recipient, msg, date) VALUE (?, ?, ?, ?)");
$stmt->bind_param("ssss", $sender, $recipient, $letter, $dateofletter);
//$conn->query($sql);
$stmt->execute();
$mysqli->close();

和文字太久
尝试这些,

word-wrap: break-word;
word-break: break-all;

但是如果您想完全具有与用户键入的相同的线路断路,那么简单地不使用CSS Word break并替换写下此 $ letter = join(“&lt; br&gt;”,explode(“ \ \) r \ n“,$ letter))); 而不是 $ letter = join(“”,Explode(“ \ r \ n”,$ letter));

或您可能需要<代码> $ letter = join(htmlspecialchars(“&lt; br&gt;“),爆炸(“ \ r \ n”,$ letter)); >

First part about PHP, I am also creating PHP website now but it's social media, and here how I did to make line breaks and also to escape chars like " or \ in my chat.

$letter = join("", explode("\r\n", $letter));
$letter = join(" \\\\ ", explode("\\", $letter));
$letter = join("\\\"", explode("\"", $letter));
$stmt = $mysqli->prepare("INSERT INTO Chat (sender, recipient, msg, date) VALUE (?, ?, ?, ?)");
$stmt->bind_param("ssss", $sender, $recipient, $letter, $dateofletter);
//$conn->query($sql);
$stmt->execute();
$mysqli->close();

and about the text too long
try these

word-wrap: break-word;
word-break: break-all;

But if you want to exactly have the same line-breaks which user typed, then simply don't use CSS word break and replace write this $letter = join("<br>", explode("\r\n", $letter)); instead of $letter = join("", explode("\r\n", $letter));

or you may need $letter = join(htmlspecialchars("<br>"), explode("\r\n", $letter));

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文