[advanced search]
Results from the most recent live auction are here.
18 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Domain Name Industry Newsletter
Go Back   NamePros.Com > Design and Development > Programming
User Name
Password

Old 04-15-2008, 12:34 PM   · #1
baris22
NamePros Member
 
Trader Rating: (0)
Join Date: Jan 2007
Posts: 64
NP$: 0.00 (Donate)
baris22 is an unknown quantity at this point
Turning multiple line breaks into one

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 Code:
$description = preg_replace('~[\r\n\s\t]+~', ' ', $description);



Edited

I did this and worked perfect

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


Please register or log-in into NamePros to hide ads
__________________

Rapidme
(rapidshare application)

Last edited by baris22 : 04-15-2008 at 12:52 PM.
baris22 is offline   Reply With Quote
Old 04-16-2008, 05:06 AM   · #2
liam_d
The original NP Emo Kid
 
liam_d's Avatar
 
Name: Liam Dawe
Location: Plymouth, UK
Trader Rating: (28)
Join Date: Jan 2005
Posts: 1,577
NP$: 124.00 (Donate)
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
Originally Posted by baris22
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 Code:
$description = preg_replace('~[\r\n\s\t]+~', ' ', $description);



Edited

I did this and worked perfect

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



You realise in that array you have "&amp;" right? so your "&"'s will be replaced too...
liam_d is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


Site Sponsors
http://www.mobisitetrader.com/ Website Header Design Bored? Visit Blugah.com! Hand-picked games added everyday!
Advertise your business at NamePros
All times are GMT -7. The time now is 11:20 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0