Welcome Guest [Log In] [Register]
Add Reply
Write string to file.; Tiny Tutorial
Topic Started: Mar 5 2009, 05:30 AM (424 Views)
GhettoFish
Member Avatar
Awesomeness FTW!
Hey just thought i should add some content to the forums. So here is a tiny tutorial on how to handle strings and how to write to file.

Code:
 

<?php
// You can store a string like this
$string = "This is my string ";
echo $string;
// And you can add data to this string like this.
$string .= "- This ";
$string .= "is more ";
$string .= "Data that ";
$string .= "i have added";
echo $string;
?>


By adding data like this to a string it is easy to handle it when we write it to our file.
We can do this either by using the fopen() or file_put_content($filename, $string) we will use fopen.s

Code:
 

<?php
// You can store a string like this
$string = "This is my string ";

// And you can add data to this string like this.
$string .= "- This ";
$string .= "is more ";
$string .= "Data that ";
$string .= "i have added";

$filename = "file.txt";
// "w" gives us write access to the file, if the file doesn't exist fopen will create the file.
$filehandle = fopen($filename, 'w') or die("can't open file");
// writes string to file
fwrite($filehandle, $string);
fclose($filehandle);
?>


So there we go, with this short little nit bit of code we have a nice text-file with inputted data.
Hurrah! :)
I'm not young enough to know everything.
- J.M. Barrie
http://www.cixz.org/
Offline Profile Quote Post Goto Top
 
Samael88
Member Avatar

Not that I know much about web-based programming, but would it not be nice if you wrote what language you used in the tutorial? :-/
It would sure help us who does not have a clue :$
Offline Profile Quote Post Goto Top
 
PauloMillerz
Member Avatar

Quote:
 
<?php
hehehe
Edited by PauloMillerz, Mar 5 2009, 01:38 PM.
If you like... RATE IT!! Add to my reputation to the left?
Quote:
 
Bidet to you sir!

Posted Image
Offline Profile Quote Post Goto Top
 
Samael88
Member Avatar

PauloMillerz
Mar 5 2009, 01:37 PM
Quote:
 
<?php
hehehe
I just have to answer that. People say that it is the sight that goes first ^_^
Offline Profile Quote Post Goto Top
 
Darksorrow131

Did you miss 's' in the function name? iirc it's file_put_contents()
(let loop () (loop))
((lambda (x) (x x)) (lambda (x) (x x)))
(let ((k #f)) (call/cc (lambda (cc) (set! k cc)) (k))
((call/cc call/cc) (call/cc call/cc))

-- Infinite loops are awesome! --
Tell me if you have other awesome infinite loops!
Offline Profile Quote Post Goto Top
 
GhettoFish
Member Avatar
Awesomeness FTW!
aah ok, well i have never used that function efore so i chose not to write about it :)
So spelling mistakes are expected :P
I'm not young enough to know everything.
- J.M. Barrie
http://www.cixz.org/
Offline Profile Quote Post Goto Top
 
Darksorrow131

lol
I like file_put_contents() though, pretty convenient function imo. Maybe it's just me being liking "with-output-to-file" in scheme too much :P
Edited by Darksorrow131, Mar 6 2009, 09:28 PM.
(let loop () (loop))
((lambda (x) (x x)) (lambda (x) (x x)))
(let ((k #f)) (call/cc (lambda (cc) (set! k cc)) (k))
((call/cc call/cc) (call/cc call/cc))

-- Infinite loops are awesome! --
Tell me if you have other awesome infinite loops!
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Web-Based Programming Support · Next Topic »
Add Reply

Banner and Logo by TheKeith