473,786 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

blank lines

how can i split by blank lines?

split(\r\n\r\n, $arr)

like this?
Aug 10 '08 #1
4 1376
sskk wrote:
how can i split by blank lines?
split(\r\n\r\n, $arr)
like this?
you can slip by a linebreak, but you will have to make sure what the
linebreak look like. Since different applications and operating systems
code a linebreak in different ways it is probably a good idea to have a
preg_replace inside the split, converting all linebreaks that might occur
to the one you split by.
Aug 11 '08 #2
On Aug 11, 8:32*am, arkascha <no_spam@no_spa m.orgwrote:
sskk wrote:
how can i split by blank lines?
split(\r\n\r\n, $arr)
like this?

you can slip by a linebreak, but you will have to make sure what the
linebreak look like. Since different applications and operating systems
code a linebreak in different ways it is probably a good idea to have a
preg_replace inside the split, converting all linebreaks that might occur
to the one you split by.
First of all, split takes a string and an array so you should quote
the line break:
split("\n", $arr);

Unix has \n linebreaks, Windows has \r\n and Mac may have \r
linebreaks.

split("\n", $arr) works on both Unix and Windows, but in Windows the
array will still contain \r at the end.

Something like this will work with \n, \r, \r\n and \n\r:
$lines = preg_split("^[\r\n]+^", $contents);
Aug 11 '08 #3
On Aug 11, 10:05*am, Sjoerd <sjoer...@gmail .comwrote:
First of all, split takes a string and an array so you should quote
the line break:
split("\n", $arr);

Unix has \n linebreaks, Windows has \r\n and Mac may have \r
linebreaks.

split("\n", $arr) works on both Unix and Windows, but in Windows the
array will still contain \r at the end.

Something like this will work with \n, \r, \r\n and \n\r:
$lines = preg_split("^[\r\n]+^", $contents);
I see now that I misunderstood your question. So my previous post is a
fine answer, but not to your question.
Aug 11 '08 #4
Thanks.
Aug 13 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3291
by: dan glenn | last post by:
Hi. I'm finding that if I have text entered into a <textarea ...> </textarea> in a form, and that text has leading blank lines (with no spaces or anything else), that when I retrieve the entered text, I lose the leading blank line. Each time it goes through a post any top-leading blank line is lost. Only one- if I have several blank lines in a row at the top, only the first is lost. (If the top blank line has a single space, it's handled...
6
4300
by: Ruben | last post by:
Hello. I am trying to read a small text file using the readline statement. I can only read the first 2 records from the file. It stops at the blank lines or at lines with only spaces. I have a while statement checking for an empty string "" which I understand represents an EOF in Python. The text file has some blank lines with spaces and other with blanks. Thanks a lot.
3
26382
by: puzzlecracker | last post by:
I want to read lines and skip blank lines: would this work considering the lines can contain tabs, spaces, etc.? file.in: ------ line1 line2
6
5540
by: Melissa | last post by:
Does anyone have a generic procedure for adding blank lines to reports like Sales details, PO details and/or Orders details. The procedure would need to count the number of line items, determine the remaining page to fill and print blank lines with the same number of fields as the line items. In addition, if there were a long list of line items that carried over to a second and possibly more pages, to print blank lines at the last page. The...
4
3240
by: Ryan S | last post by:
I am trying to read an XML document generated by a web server using the XMLTextReader class, but the document generated appears to have some blank lines at the top that are causing problems. If I connect directly to the URL, when I call the ".Read" method on the XMLTextReader, I get the message: "The XML declaration is unexpected. Line 8, Column 3" If I open the URL in my browser and copy and paste the XML stuff (starting
3
3706
by: Jeff Calico | last post by:
Hello everyone I am transforming an XML document to text, basically only outputting a small portion of it. When I run the following XSLT via Xalan's processor, I get a bunch of unwanted blank lines in the output. Here is a simplified XML and XSLT: (Note the problem does not happen when testing in XMLSpy) - - - - - - - - - - - - - - - - - - - - - - - -
1
1806
by: satya.mahesh | last post by:
Hi All, I am working on a problem which "eliminates blank lines in export (between headings and when a heading is empty)". I want a macro which will do this job for me. For e.g: Heading1 Heading2
1
2971
by: DAnne | last post by:
Hi, I have checked your archives but have not been able to find anything that works for my situation. I have a for loop that brings back a list of unique responses for each section in a report. These responses are responses to each question in a particular section. This is working fine. However the output prints many blank lines. I have determined that these lines are are actually places where the question had the same response as a...
4
2877
by: Andreas Bauer | last post by:
Hi, I have to audit some c# code. I know in the options I can adjust how the code should be formatted while entering it. But is there any way to apply afterwards a code template to the classes to adjust their appearance (except ctrl-k ctrl-f)? Foremost how to clear unnecessary blank lines, e.g reduce 4 blank lines to one. I don´t want to change every class manually. Thanks in advance for any hint.
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.