sql查询将新行字符转换为html< br> [英] sql query to convert new line character to a html <br>
问题描述
我有一个mysql数据库文章,没有格式化输入textarea,它们只用一个换行符换行
\\\
我需要将所有这些转换为html br标记
< br />
你可以帮我写一个查询来做到这一点,我可以在phpmyadmin中运行这样做吗?
表的名字是
exp_channel_data
$ b $ p 是否有一个查询我可以运行,将剥离所有p和span中的标签
我想摆脱这种情况东西
< p class =MsoNormalstyle =MARGIN:0in 0in 0pt>
< span face =Times New Roman>
并以此结束
< p为H.
< span>
解决方案第一个问题:
UPDATE SET exp_channel_data = text_column REPLACE(text_column, '\r\\\
', '<峰; br />')
如果它不能代替任何东西,请改用'\\\
'
'\r\\\
'
。
第二个问题:
你无法通过SQL查询来完成这项工作,你必须将这些数据提取到PHP脚本或其他任何你喜欢的内容中,然后执行一个正则表达式替换(例如PHP):
$ new_str = preg_replace函数( '#≤(p |跨度)[^>] +>#',< $ 1 GT ;',$ old_string);
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>
解决方案 First question:
UPDATE exp_channel_data SET text_column = REPLACE(text_column, '\r\n', '<br />')
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):
$new_str = preg_replace('#<(p|span)[^>]+>#', '<$1>', $old_string);
这篇关于sql查询将新行字符转换为html< br>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!