sql 查询将换行符转换为 html
我有一个 mysql 数据库,其中的文章被输入到没有格式的文本区域中,它们仅使用换行符作为换行符,
\n
我需要将所有这些转换为 html br 标签,
<br />
你能帮我编写一个查询来执行此操作吗?在 phpmyadmin 中运行可以做到这一点吗?
表的名称是
exp_channel_data
一个额外的问题...
是否有一个我可以运行的查询,它将删除 p 和 span 标签中间的所有内容
我想摆脱这些东西
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
<span face="Times New Roman">
并最终得到这个
<p>
<span>
I have a mysql database of articles that were entered into a textarea with no formatting, they use only a newline character for line breaks
\n
I need to convert all of these into html br tags
<br />
can you help me write a query to do this that I can run in phpmyadmin that will do this?
the name of the table is
exp_channel_data
as a bonus question...
Is there a query I can run that will strip everything out of the middle of p and span tags
I want to get rid of this stuff
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
<span face="Times New Roman">
and end up with just this
<p>
<span>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
第一个问题:
如果它不能替换任何内容,请使用
'\n'
而不是'\r\n'
。第二个问题:
你不能使用 SQL 查询来做到这一点,你必须将此数据提取到 PHP 脚本或任何你喜欢的其他内容中,并执行正则表达式替换(PHP 示例):
First question:
If it doesn't replace anything, use
'\n'
instead of'\r\n'
.Second question:
You can't do it with a SQL query, you have to fetch this data into a PHP script, or anything else you like, and perform a regular expression replace (example for PHP):
这适用于你的第一个问题。
This works for your first question.
由于您使用的是 ExpressionEngine,因此只需将每个字段的格式更改为 XHTML 即可。当显示在前端时,它将添加
标记。一定要保持数据干净,并将格式留给显示它的解析器。Since you're using ExpressionEngine, you can just change the format of each field to XHTML. It will add the
<br />
markup when displayed on the front-end. bet to keep your data clean and leave the formatting to the parser displaying it.如果有人碰巧寻找 PHP 端解决方案,请使用 nl2br 函数...它对我有用。它在运行时将那些讨厌的换行符转换为 HTML
标记。https://www.w3schools.com/PHP/func_string_nl2br.asp
IF someone happens to look for a PHP-side solution, use the
nl2br
function... it worked for me. It converts those nasty line breaks to HTML<br>
tags during runtime.https://www.w3schools.com/PHP/func_string_nl2br.asp