Sponsored Content
Full Discussion: CRLF to LF PHP
Top Forums Web Development CRLF to LF PHP Post 302587950 by Corona688 on Friday 6th of January 2012 11:04:07 AM
Old 01-06-2012
Some systems translate \n into \r\n for you when you write to text files, so I wasn't sure your string even contained \r\n in the first place.

Knowing for sure that string replacement will actually work here, I'd do this to delete all carriage returns:

Code:
$input=strtr($input, array("\r" => ""));

Nothing wrong with the way you're doing it, though. This may be slightly more efficient but I don't think it's a big deal.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add CRLF is probably simple!

I am building a script that will execute programs using records/fields in a file as arguments. Before I start testing that, I am working on reading the file properly and using printf to display the fields in the file. I used typeset to format my output. Now all I need is to figure out how to... (1 Reply)
Discussion started by: Skyybugg
1 Replies

2. AIX

CRLF during SFTP transfer is appearing only in one server

Hello. I have got 3 unix boxes A B C. Box A is being used to prepare some reports. After the reports generation, Box A sftp the reports to Box B and Box C. When I look at the report in Box B and Box C. The reports are different. In Box B, I see using od -x command there is CRLF (\r\n) at the end... (7 Replies)
Discussion started by: panchpan
7 Replies

3. Shell Programming and Scripting

Converting hex value 7C (for pipe) to CRLF in Unix

I am trying to convert a txt file that includes one long string of data. The lines are separated with hex value 7C (for pipe). I am trying to process this file using SQR (Peoplesoft) so I thought the easiest thing to do would be to replace the eol char with a CRLF in unix so I can just... (4 Replies)
Discussion started by: sfedak
4 Replies

4. Shell Programming and Scripting

Issue with a file that contains CRLF

I have a nawk that reads in a log file and outputs a file that matches my search. IFS=" " while read record do `echo $record | nawk 'BEGIN { FS=" " } { type_record=substr($0, 1, 1); if (... (14 Replies)
Discussion started by: Pablo_beezo
14 Replies

5. Homework & Coursework Questions

Convert ASCII Text, with CRLF

1. The problem statement, all variables and given/known data: write a script asciiFix.sh that takes an arbitrary number of file paths from the command line and carries out the same analysis on each one. If a file is not Windows ASCII, your script should do nothing to it. For each file that is... (7 Replies)
Discussion started by: kwatt019
7 Replies

6. Shell Programming and Scripting

Appending CRLF to end of record

I need to append |\r\n (a pipe character and CRLF) at end of each record in Unix to all records where they are not already present. So first check for the presence of |\r\n and if absent append it else do nothing (3 Replies)
Discussion started by: abhilashnair
3 Replies

7. Shell Programming and Scripting

Sorting file with CRLF within field, RS=$

OK below is what my sample file looks like. I need to sort by the Primary Key ie: {1:F01SAESVAV0AXXX0466020126} in the first record. Record seperator is $. I tried sort, but it completely messes it up. I am thinking I will need to use something like awk which understands the record seperator... (6 Replies)
Discussion started by: alfredo123
6 Replies

8. Shell Programming and Scripting

Removing CRLF combo but not CR or LF when alone

What is the command or script to remove CRLF but only when joined? Tried using below but removed all instances of either cat a.txt | tr -d "\r\n" > b.txt (14 Replies)
Discussion started by: qqp
14 Replies

9. Shell Programming and Scripting

Replace CRLF between pipe (|) delimiter with LF

Hi Folks! Need a solution for the following :- Source data ------------- 123|123|<CRLF><CRLF><CRLF>|321<CRLF> Required output ------------------ 123|123|<LF><LF><LF>|321<CRLF> <CRLF> represents carriage return <LF> represents line feed Being hunting high and low for a... (10 Replies)
Discussion started by: hishamzz
10 Replies
ARRAY_UNIQUE(3) 							 1							   ARRAY_UNIQUE(3)

array_unique - Removes duplicate values from an array

SYNOPSIS
array array_unique (array $array, [int $sort_flags = SORT_STRING]) DESCRIPTION
Takes an input $array and returns a new array without duplicate values. Note that keys are preserved. array_unique(3) sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted $array will be kept. Note Two elements are considered equal if and only if (string) $elem1 === (string) $elem2 i.e. when the string representation is the same, the first element will be used. PARAMETERS
o $array - The input array. o $sort_flags - The optional second parameter $sort_flags may be used to modify the sorting behavior using these values: Sorting type flags: o SORT_REGULAR - compare items normally (don't change types) o SORT_NUMERIC - compare items numerically o SORT_STRING - compare items as strings o SORT_LOCALE_STRING - compare items as strings, based on the current locale. RETURN VALUES
Returns the filtered array. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ |5.2.10 | | | | | | | Changed the default value of $sort_flags back to | | | SORT_STRING. | | | | | 5.2.9 | | | | | | | Added the optional $sort_flags defaulting to | | | SORT_REGULAR. Prior to 5.2.9, this function used | | | to sort the array with SORT_STRING internally. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 array_unique(3) example <?php $input = array("a" => "green", "red", "b" => "green", "blue", "red"); $result = array_unique($input); print_r($result); ?> The above example will output: Array ( [a] => green [0] => red [1] => blue ) Example #2 array_unique(3) and types <?php $input = array(4, "4", "3", 4, 3, "3"); $result = array_unique($input); var_dump($result); ?> The above example will output: array(2) { [0] => int(4) [2] => string(1) "3" } SEE ALSO
array_count_values(3). NOTES
Note Note that array_unique(3) is not intended to work on multi dimensional arrays. PHP Documentation Group ARRAY_UNIQUE(3)
All times are GMT -4. The time now is 04:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy