/    Sign up×
Community /Pin to ProfileBookmark

Detect ascii Line breaks, including hex, etc

I have a program which uploads ascii format files, parses the lines,and does some stuff. I can parse by breaking into array with explode(“n”,”fileContent”,) or doing the same with “r”, but i don’t konw how to test for all of the other line breaks, such as “0XOA”, ascii character 10, etc (see post from wiki below). anyone have experience with this ?

[SIZE=”2″]Systems based on ASCII or a compatible character set use either LF (Line feed, ‘n’, 0x0A, 10 in decimal) or CR (Carriage return, ‘r’, 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, ‘rn’, 0x0D 0x0A). These characters are based on printer commands: The line feed indicated that one line of paper should feed out of the printer, and a carriage return indicated that the printer carriage should return to the beginning of the current line. Some rare systems, such as QNX before version 4, used the ASCII RS (record separator, 0x1E, 30 in decimal) character as the newline character.
LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others. However, in tty ‘raw mode’, CR+LF is used for output and CR is used for input.
CR+LF: DEC TOPS-10, RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS (MS-DOS, PC-DOS, etc.), Atari TOS, OS/2, Microsoft Windows, Symbian OS, Palm OS
CR: Commodore 8-bit machines, TRS-80, Apple II family, Mac OS up to version 9 and OS-9
RS: QNX pre-POSIX implementation.[/SIZE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 28.2011 — You can use preg_split, creating a regexp to split on, e.g. for newline, carriage return, and/or 0x0A:
[code=php]
$array = preg_split('#[nrx0A]+#', $string);
[/code]
×

Success!

Help @mparker1113 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...