PHP, \n, and file formats

lomn75

Purple Ace
Joined
Jun 26, 2000
Messages
6,613
Is there a way to get PHP to deal with an input file independently of OS encoding? I'm trying to filter based on \n but get crap when stuff like \r comes into the picure. I'd prefer to stick to explode() rather than regular expressions, though I can convert over.
 
what exactly are you trying to do? get an array of the lines of the file? if so, then file() will do that. if you don't want the newlines attached, then you can
Code:
foreach($lines as $k => $v) {
    $lines[$k] = rtrim($v);
}
 
pr0pensity said:
Use str_replace(). Replace \r\n with \r and \r with \n.
Ahh, thanks.

//edit: I do care about placement, as I'm parsing multi-line chunks of arbitrary content. I usually key off of stuff like \nParticularTag\n since ParticularTag could also appear as internal data. Multi-line rules out the line-by-line solution, and explode() isn't flexible enough to handle all the possible newline possibilites.
 
Back
Top