473,378 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

blank lines

how can i split by blank lines?

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

like this?
Aug 10 '08 #1
4 1365
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_spam.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
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...
6
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...
3
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
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...
4
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...
3
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...
1
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 ...
1
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....
4
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.