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>
SQL Server ' AS 'New Line' -- using carriage return: CHAR(13) SELECT 'First line. '+ CHAR(13) + 'Second line. ' AS 'New Line' -- Using both: CHAR(13)+CHAR(10) SELECT 'First line. '+ CHAR(13)+CHAR(10) + 'Second line.
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.
CRLF (Carriage Return and Line Feed)f in a SQL statement is replaced by just a LF.
Remove and Replace Carriage Returns and Line Breaks in SQL Using SQL to remove a line feed or carriage return means using the CHAR function. A line feed is CHAR(10); a carriage return is CHAR(13).
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);
UPDATE yourTable SET text=REPLACE(text,"\n","<br />")
This works for your first question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With