How can i delete a blank line PHP [duplicate] - php

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);

Related

REGEX with PHP (what am I doing wrong?) [duplicate]

This question already has answers here:
How do I match any character across multiple lines in a regular expression?
(26 answers)
Closed 3 years ago.
Let's say I want to place the bold content into a variable called $question_text.
1} What color is the sky:
A) Answer A
B) Answer B
C) Answer C
Answer: A
How do I use preg_match to do that?
I tried:
if(preg_match("#}(.*)#", $question, $question_match))
{
//Extract the question text
$question_text = trim($question_match[1]);
But it only gives me the first line: **What color is the sky: **
What am I doing wrong?
#(?s)}(.*)+?Answer: [A-Z]#
Worked for me!

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)

SQL Insert line break [duplicate]

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

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