Replace Break Line With '\n'
I need help for replacing line breaks in my mysql database with \n. If I copy mysql text and past in MS Word, I have this: I need to replace the break lines with \n. Like this: T
Solution 1:
In Php there is a function named nl2br
echo nl2br("hello\nWorld");
and the result is
hello<br/>World
In sql there is a function named REPLACE
UPDATE yourtable SET field=REPLACE(REPLACE(field, CHAR(13), ''), CHAR(10), '')
And Finally in javaScript you have replace
too
myString = myString.replace(/\r?\n/g, "");
Good Luck
Solution 2:
If MS Word is parsing the text with linebreaks, it means it already has them.
Use a text editor like notepad++ and set it to show all characters. You will see what special chars are being used as linebreaks (it might be \n, \r and a mix of both).
They won't show up when you browse your database with phpmyadmin, because its textarea control will parse the linebreaks for you.
Solution 3:
I am not sure if I understand your input string correctly, but if, the code would look like this.
function replace_lb($str){
return str_replace(array(chr(10), chr(13)), '\n', $str );
}
Usage:
$query = mysql_query('SELECT `id`,`value` FROM table ', $link);
while ($result = mysql_fetch_array($query)){
mysql_query('UPDATE table SET `value`= "'.replace_lb($result['value']).'" WHERE id="'.$result['id'].'"', $link);
}
The code could use some optimalization, but I think it will suit your needs
Solution 4:
try the php nl2br
<?php
$result = nl2br($row['MYSQL_RESULT']); // from the return from your query
?>
Post a Comment for "Replace Break Line With '\n'"