SQL Insert line break [duplicate] - php

This question already has answers here:
Adding a line break in MySQL INSERT INTO text
(12 answers)
Closed 9 years ago.
How can i insert line break by a variable inserting into mysql?
$delattn = $row_Recordset_delattn['Cus_fname'].' '.$row_Recordset_delattn['Cus_lname'].',
'.$row_Recordset_delattn['Cus_designation'].',
LINE BREAK
'.$row_Recordset_delattn['Cus_department'];

Simply add a "\n" where you want a line break
$delattn = $row_Recordset_delattn['Cus_fname'].' '.$row_Recordset_delattn['Cus_lname'].','.$row_Recordset_delattn['Cus_designation'].', \n '.$row_Recordset_delattn['Cus_department'];
Use PHP's
nl2br()
function to translate that line break into a
<br />
tag in HTML. More info here

Related

How can i delete a blank line PHP [duplicate]

This question already has answers here:
Remove new lines from string and replace with one empty space
(21 answers)
Closed 7 years ago.
I have this lines so i need delete blank line:
Fichier TESTTT
testt have that
I've used str_replace('\r\n','',$text); but always I have this line blank
Thanks in advance
try this
preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);

Saving \n as <br> to database from textarea [duplicate]

This question already has answers here:
Preserve Line Breaks From TextArea
(7 answers)
Closed 7 years ago.
I tried this but it's not chaning new lines to < br >
<textarea name="addesc" id="addesc"><?php echo $data['addesc']; ?></textarea>
$data['addesc'] = preg_replace("/\r\n|\r/", "<br />", $_POST["addesc"]);
$data['addesc'] = trim($data['addesc'])
As such there's no $_POST["addesc"] on the post.php page. There's $_POST["do"]. I tried it too. No results.
There is a php function for that called nl2br.
Btw. searching for "new line to br" would have been very easy and brings up certain related topics on SO and the php manual of nl2br:
How to replace \r & \n with <br/>?

MYSQL Trim function using on PHP [duplicate]

This question already has answers here:
Php trim string at a particular character
(7 answers)
Closed 8 years ago.
I have a mysql codes which i need to do that trim and leading with PHP, anyone know how to write below logics with PHP code.
LEFT(TRIM(LEADING 'DHL ' FROM CONT_NAAM),20)
TRIM(LEADING 'DHL JVGL' FROM CONT_NAAM)
You can use preg_replace:
substr(preg_replace('/^(DHL )+/', '', $cont_naam), 1, 20)

Php nl2br show /r/n [duplicate]

This question already has answers here:
How to use nl2br() to handle string with '\r\n'?
(4 answers)
Closed 8 years ago.
When I use the function nl2br like result I see /r /n
example:
in a textarea I wrote
Hello,
how are you?,
fine
php
echo nl2br($_POST['message']);
result to screen
\r\nHello,
\r\nhow are you?
\r\nfin
how can I fix it? thank you
try this:
$newmessage = preg_replace('#(\\\r|\\\r\\\n|\\\n)#','<br />', $_POST['message']);

How to wrap a long text having no spaces in php [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to wrap long lines without spaces in HTML?
I have a long text "jkjkllllllllljcsccncnmchdkcjhvcjdkvk".how to wrap this text in php
Use this:
<?php
$iamlong = "woooooooooooord.";
$iamwrapped = wordwrap($iamlong , 8, "<br>", true);
echo $iamwrapped;
?>

Categories