NameSilo

Turning multiple line breaks into one

Spaceship Spaceship
Watch

baris22

Established Member
Impact
1
Hello,

How can i change two or more than 2 line breaks into one?

I am using this for spaces and it works perfect but i do not know how to do for line breaks

PHP:
$description = preg_replace('~[\r\n\s\t]+~', ' ', $description);


Edited

I did this and worked perfect

PHP:
$to_replace = array("\r\n","|","\n","\\r\\n","\\n","&");
$description = str_replace($to_replace, "\n", $description);
$description = preg_replace('~[\n]+~', '<br>', $description);
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
baris22 said:
Hello,

How can i change two or more than 2 line breaks into one?

I am using this for spaces and it works perfect but i do not know how to do for line breaks

PHP:
$description = preg_replace('~[\r\n\s\t]+~', ' ', $description);


Edited

I did this and worked perfect

PHP:
$to_replace = array("\r\n","|","\n","\\r\\n","\\n","&");
$description = str_replace($to_replace, "\n", $description);
$description = preg_replace('~[\n]+~', '<br>', $description);

You realise in that array you have "&" right? so your "&"'s will be replaced too...
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back