Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

fprintf(3) [php man page]

FPRINTF(3)								 1								FPRINTF(3)

fprintf - Write a formatted string to a stream

SYNOPSIS
int fprintf (resource $handle, string $format, [mixed $args], [mixed $...]) DESCRIPTION
Write a string produced according to $format to the stream resource specified by $handle. PARAMETERS
o $handle -A file system pointer resource that is typically created using fopen(3). o $format - See sprintf(3) for a description of $format. o $args - o $... - RETURN VALUES
Returns the length of the string written. EXAMPLES
Example #1 fprintf(3): zero-padded integers <?php if (!($fp = fopen('date.txt', 'w'))) { return; } fprintf($fp, "%04d-%02d-%02d", $year, $month, $day); // will write the formatted ISO date to date.txt ?> Example #2 fprintf(3): formatting currency <?php if (!($fp = fopen('currency.txt', 'w'))) { return; } $money1 = 68.75; $money2 = 54.35; $money = $money1 + $money2; // echo $money will output "123.1"; $len = fprintf($fp, '%01.2f', $money); // will write "123.10" to currency.txt echo "wrote $len bytes to currency.txt"; // use the return value of fprintf to determine how many bytes we wrote ?> SEE ALSO
printf(3), sprintf(3), sscanf(3), fscanf(3), vsprintf(3), number_format(3). PHP Documentation Group FPRINTF(3)

Check Out this Related Man Page

REWIND(3)								 1								 REWIND(3)

rewind - Rewind the position of a file pointer

SYNOPSIS
bool rewind (resource $handle) DESCRIPTION
Sets the file position indicator for $handle to the beginning of the file stream. Note If you have opened the file in append ("a" or "a+") mode, any data you write to the file will always be appended, regardless of the file position. PARAMETERS
o $handle - The file pointer must be valid, and must point to a file successfully opened by fopen(3). RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 rewind(3) overwriting example <?php $handle = fopen('output.txt', 'r+'); fwrite($handle, 'Really long sentence.'); rewind($handle); fwrite($handle, 'Foo'); rewind($handle); echo fread($handle, filesize('output.txt')); fclose($handle); ?> The above example will output something similar to: Foolly long sentence. SEE ALSO
fread(3), fseek(3), ftell(3), fwrite(3). PHP Documentation Group REWIND(3)
Man Page

15 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script help

I have two files, gmrd.txt and core_extract.txt I need awk to look at the first column of each file and if a field appears in core_extract that also appears in gmrd.txt then it should write append that line to a file here is what i have so far...currently it replaces the line found with... (23 Replies)
Discussion started by: penfold
23 Replies

2. Shell Programming and Scripting

sed query

I have a series of folders /temp/a /temp/b /temp/c In folders a, b, and c, I have files a1.txt..........a20.txt b1.txt..........b40.txt & c1.txt..........c60.txt Each file has the same data format :- Line 1 AAAAA aaaa Line 2 BBB bbbbbb Line 3 CCCC cccccc Etc etc I need to write a... (13 Replies)
Discussion started by: grinder182533
13 Replies

3. Shell Programming and Scripting

date

file1 E108,0,2/3/1995,0,E001,E003,A,15000,1250,7.211538,12/14/2008 E109,0,2/15/1995,0,E001,E001,A,78000,6500,37.5,2/3/1995 resultant date should be in this formate E108,0,199523,0,E001,E003,A,15000,1250,7.21153820081214 E109,0,1995215,0,E001,E001,A,78000,6500,37.5,199523 Is the any... (10 Replies)
Discussion started by: charandevu
10 Replies

4. Shell Programming and Scripting

creating files and getting input from another file

I have a file where i have files name with absolute path. Ex: files.dat and contents are: /root/xy/yz/zz/abc.txt /root/xx/yy/zz/ac.txt /root/xz/yz/zx/bc.txt /root/xy/yz/zx/abcd.txt now i want to create all above files(dummy files and can be 0 byte). i thought of using touch but it doesn't... (10 Replies)
Discussion started by: ajayyadavmca
10 Replies

5. UNIX for Dummies Questions & Answers

Replacing string

Hi there, I'd like to replace STRING_ZERO in FILE_ZERO.txt with the value of VALUEi-th by using something like that: VALUE1=1000 VALUE2=2000 VALUE3=3000 for((i=1;i<=3;i++)); do sed "s/STRING_ZERO/$VALUE'$i'/" FILE_ZERO.txt >> FILE_NEW.txt; done but it doesn't work... Any help... (9 Replies)
Discussion started by: Giordano Bruno
9 Replies

6. Shell Programming and Scripting

Need to change format of number

Hi, using a shell script to get values from a CSV eg: 12345.67,5678990.89,76232882.90 12345,5678990.89,76232882 Need the format of these numbers to change to 12,345.67:5,678,990.89:76,232,882.90 12,345:5678990.89:76232882 Using nawk on solaris, to parse these values, need the... (10 Replies)
Discussion started by: pgop
10 Replies

7. Shell Programming and Scripting

Numerically sort problem for a long list of file name

I got a long list of file name. My input: data_1.txt data_2.txt data_3.txt data_10.txt data_21.txt data_12.txt data_4.txt My desired output: data_1.txt data_2.txt data_3.txt data_4.txt data_10.txt data_12.txt data_21.txt Does anybody got idea how to archive it? (11 Replies)
Discussion started by: patrick87
11 Replies

8. Shell Programming and Scripting

Automatic file input to code

i have got many files like this in my folder temp(say) imp_02042008.txt for date 02-04-2008 imp_03092009.txt for date 03-09-2009 imp_25112009.txt for date 25-11-2009 ................... ........ in some folder. and one of my shell code uses one of the above files based on date.... (9 Replies)
Discussion started by: Maruti
9 Replies

9. Shell Programming and Scripting

if file is NOT empty, then append content to file

hi people, i have texts down.txt and down-new.txt and i want to check; - if down-new.txt is NOT empty, then write date and its content to /home/gc_sw/down.txt for example; down.txt:AAAA SSSS down-new.txt:123 456 and after checking down-new.txt is NOT empty, down.txt should... (10 Replies)
Discussion started by: gc_sw
10 Replies

10. UNIX for Dummies Questions & Answers

replacing a string with another string in a txt file

Dear all, I have a file like below. I want to replace all the '.' in the 3rd column with 'NA'. I don't know how to do that. Anyone has an iead? Thanks a lot! 8 70003200 21.6206 9 70005700 17.5064 10 70002200 . 11 70005100 19.1001 17 70008000 16.1970 32 70012400 26.3465 33... (9 Replies)
Discussion started by: forevertl
9 Replies

11. Shell Programming and Scripting

File Concatenation in a format

I have some files named as: error_abc.txt error_def.txt error_ghi.txt I want to concatenate all these into a single file say error_all.txt. The error_all.txt should be displayed like: ... (11 Replies)
Discussion started by: ankur328
11 Replies

12. Shell Programming and Scripting

Help with Creating file based on conditions

Can anyone please assist? I have a .txt file(File1.txt) and a property file(propertyfile.txt) . I have to read the vales from the property file and .txt file and create the output file(outputfile.txt) mentioned in the attachment. For each record in .txt file,the below mentioned values shall be... (20 Replies)
Discussion started by: vinus
20 Replies

13. Shell Programming and Scripting

Korn Shell manipulating the string into dynamic currency number

Conversion of string into currency value.. ex1: number_of_positions=2 input_string=345987 Output= 345,987.00 ex2: number_of_positions=4 input_string=1345987 Output= 1,345,987.0000 Please respond as soon as possible edit by bakunin: we will gladly respond as soon as... (15 Replies)
Discussion started by: suren.bills
15 Replies

14. Windows & DOS: Issues & Discussions

Simple 'date' to 001 scheme script

So since I'm looking for an easy way to numberize files in a folder according to date: Is there an easy script (batch, windows), that will rename files like this: .earliest creation time: 001.file older creatiin time : 002.file even older time : 003.file .... ... .. . ... (10 Replies)
Discussion started by: pasc
10 Replies

15. Shell Programming and Scripting

How can I extract digits at the end of a string in UNIX shell scripting?

How can I extract digits at the end of a string in UNIX shell scripting or perl? cat file.txt abc_d123_4567.txt A246_B789.txt B123cc099.txt a123_B234-012.txt a13.txt What can I do here? Many thanks. cat file.txt | sed "s/.txt$//" | ........ 4567 789 099 012 13 (11 Replies)
Discussion started by: mingch
11 Replies