kakingho
Jul 17 2006, 04:34 PM
| | QUOTE <?php
$fp=fopen("test.txt","a"); fputs($fp,"ok"); ?>
The above method is only to add "ok" at the end (DO NOT write on a new line)
I want to know... How to add data on a new line and at the end of txt file??!
thx~ |
Reply
electriic ink
Jul 17 2006, 07:29 PM
It would be : CODE <?php
$fp = fopen ("test.txt", "a"); fputs ($fp, "ok \nnewline"); ?> So yeah, basically, you just add \n but the one things I've found is that the \n must be in " NOT '
Reply
galexcd
Jul 18 2006, 02:28 AM
I have even noticed that in php strings can acctualy have a real carrage return! Instead of the \n u can just make the string on two lines! Sorta figured that one out on accident. Example: CODE <?php
$fp = fopen ("test.txt", "a"); fputs ($fp, "ok newline"); ?>
Reply
electron
Jul 18 2006, 06:36 AM
Here is a better File writing function : CODE <?php $filename = 'test.txt'; $somecontent = "Add this to the file\n";
// Let's make sure the file exists and is writable first. if (is_writable($filename)) {
// In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; }
// Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle);
} else { echo "The file $filename is not writable"; } ?> Also you should use the \n thing to hit enter in a file. But i dont think so it is necessary to put it in "" double quotes rather than single quotes . Best of luck
Reply
kakingho
Jul 18 2006, 02:29 PM
..thx a lot~~ successful!
Reply
electron
Jul 19 2006, 04:23 AM
You can also find a way to modify a existing file to change some of its values. e.g. If you have a global file that controls all your site settings and would like to modify it via the Admin Center you can use str_repalce function to do so. It is very effective for users. Good luck
Reply
Florisjuh
Jul 19 2006, 04:10 PM
Thanks electron for the nice and very good usable PHP script, keep them coming  )
Reply
electron
Jul 20 2006, 02:54 AM
What type of code or function do youy want ? I can help you. By the way you can also use preg_replace() fucntion if you are not so sure of the TEXT MATTER but no the Format of it e.g. a Hyperlink. But if you know the text then its advisable to use str_replace() function. Also for inserting any kind of quote - single or double - use a backslash to write it in the file. I love PHP
Reply
Spectre
Jul 20 2006, 03:15 PM
A like PHP. I wouldn't go so far as to say I love it. Just a little expansion and clarification. preg_replace() uses the Perl-compatible regular expression engine built into PHP (as do all preg_ functions) to perform a regex search and replace operation on a given string, where the subject is searched for a pattern matching that given and replaced with the specified replacement (which can contain backreferences to the pattern matched). str_replace() is just a very simple static search and replace function for strings, where it replaces all given instances of one string within another with a specified value. preg_replace() is so much more powerful due to its harnessing PCRE - however, this means it is also slower, and should not be used unless required. Quotes only need to be escaped when that exact character is being used as a string delimiter. For instance, the string 'a"b"c' is perfectly legal, without the double quotes being escaped, as single quotes are acting as string delimiters - however, were the double quotes single quotes instead, they would need to be escaped, for example: 'a\'b\'c'. Within single quotes, no other characters will ever be escaped other than single quotes - so '\n' remains just that, whereas "\n" is the equivalent of chr(10) (and "\r" the equivalent of chr(13)). Variables will also be substituted within double quotes - eg. "the value is $variable" will become "the value is x" (assuming x is the value of the variable $variable - if that makes any sense at all). Because of these two factors, it is better to use single quotes where possible, even if this means concatenating strings delimited via two different sets of quotes (eg. 'start' . "\n" . 'end'), as it will always be faster. Although the speed difference generally isn't noticable, it can begin to slow down if large amounts of text is being processed, or if it is happening in rapid succession (eg. the code behind a very popular website), and it's simply a good programming practice to write clean, fast and efficient code. So anyway, that's my two and half cents worth.
Reply
Similar Topics
Keywords : php, writes, txt, file
- Internal File Transfer
(5)
Free Software For File Recovery
RECUVA (3) Hi all, I was loking for a software to recover my lost files and I found this /biggrin.gif"
style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> And the best part is ,
its free Recuva - File Recovery Recuva (pronounced "recover") is a freeware Windows utility to
restore files that have been accidentally deleted from your computer. This includes files emptied
from the Recycle bin as well as images and other files that have been deleted by user error from
digital camera memory cards or MP3 players. It will even bring back files that have been d....
Where Is The Bookmarks File Stored With Ff2?
(4) My bookmarks are critical and lengthy. I'd like to save them to a flash drive, since my laptop
is ancient and it's been acting up lately. I went into the FireFox folder, but couldn't find
the bookmarks info anywhere. there's a bookmarks.html page, but it doesn't contain the
actual bookmarks. Where does FF2 store the bookmarks? Or is there an easier way to copy and paste
the bookmarks to another file? /huh.gif" style="vertical-align:middle" emoid=":huh:" border="0"
alt="huh.gif" /> 2 poor 4 a sig ....
Debug Exe Files
How to debug an exe file. (4) Think that we have written a program, and some codes are wrong. We can go back to compiler and
change the code, and compile again. But I will show you how to correct our mistakes without using
the compiler. Let's start: I have written a program in Delphi. Let's see my mistake. I
have created a form like this. After this I wrote the codes in the Compare Button click as
below. CODE 1. procedure TForm1.ComparebuttonClick(Sender: TObject); 2. var
3. a,b:integer; 4. begin 5. a := StrToInt(EditA.Text); 6. b :....
File Manager Not Working
(2) When I goto upload files using the file manager(legacy mode), the files do not upload correctly.
Every time I try to upload a file, it takes the time to upload it, but the file always comes out
being 0kb so it does not upload the file. Why is this happening?....
A Good File Explorer For Windows Xp?
what's a better alternative to explorer (6) Hi, although it has some useful features and it's (i'd hope so...) well integrated with the
shell, the file explorer that comes with windows xp is not the best we can ask for... so I've
always tried to use various other pieces of softwares randomly found on the net whenever I've
had to intensively work on my file directory... still I haven't found a very good one, all
those I tried have some kind of bug or they are not really user friendly in some occasions... would
anyone suggest a good FREEWARE file explorer? thanks /wink.gif" style="vertical-al....
Defraggler - Free Software To Defrag Your File
Try it out (12) Have you all hear a software called Defraggler? Well if not, I recommend you to download this
software. What does it do? Simple, it'll quickly defrag files you want to defrag, no need to
defrag the whole drive. Useful if you have less fragmented file and if you hate Windows's
original defragger. And it's free! OS Supported and filesystem supported? All Windows 2000
or higher (it'll be Windows 2000, 2003, XP and Vista. 64-bit support too) It support NFTS and
FAT32 Requirement? Well not much, the EXE file even smaller than 1 MB (dont judge the power ....
Qoodaa Successfully Solved Video Downloading Problems
a good large file transfer tool, (0) The rise of Video web stimulates more intuitive video feeling of large people, and makes video
downloading become a popular trend in web times. Meanwhile, more and more downloading problems arise
correspondingly, in which the first trouble is slow downloading speed and incomplete downloading. It
seems to many people that downloading video, especially downloading large video, is like a
protracted war with the internet, even the victory is difficult to predict. Many domestic video web
has succesesfully solved downloading problems that they suffered for a long time, after....
Share Qoodaa
a good large file transfer tool, (0) Knowing Qoodaa was quite by chance. A few days ago, my friends studying in America recommended me a
new popular transfer tool—Qoodaa. And he told me that it was a quite good software to download
files and movies. At first,I was skeptical, but after using it, I found it’s a good choice to
choose Qoodaa. And I have summarized the some features of Qoodaa: 1.Its speed is faster than any
other softwares I used before to upload movies. 2.It can download files quickly through downloading
links, in a word, it is time-saver and with high efficiency. 3.No limit of spac....
Issues Uploading A File [resolved]
(3) Hi there. I have been trying to upload a zip file only about 2mb to my account through CPanel.
First I tried uploading it to a new folder in public_ftp. Then i tried to put it in the main part
of public_ftp. I also tried the same thing in public_html. It shows the file being uploaded, and i
get 100 %, but alas, when i look in the folders nothing is there. Is there a restriction on .zip
files? I have had no problems as of yet uploading htm and html pages. Please let me know ASAP.
Thank you.....
Unable To Replace .png File In Directory
Can't even delete it using Cpanel (7) I can't delete a little file using file manager in Cpanel. I'm trying to delete a .png
image, actually, I'm trying to replace it. The response comes back as a success, but when I
reload my site it's still there. Then I go back to the file manager and go up a level, then back
and WOOP! There it is! I'm beyond frustrated here. What is going on?....
Make A Moderately-secure Password System Using Javascript
using file redirection to hide the password. (4) JavaScript is very handy at making forms, allowing for much more customization and easier ways to
send data. So making Login forms using JavaScript may seem to many to be a very feasable idea.
However, JavaScript is very bad at protecting Passwords, as since the passwords are not encypted and
the whole JavaScript code is in the page, a person could just view the Page Source and find out
everything. Even if you use an external JavaScript, it would still be poor as the file name for the
external JavaScript would still be revealed. But I have an answer! There is a rela....
Php Configuration File
"config.php" (16) I did create this topic mainly because I want to know everything about that configuration file. I
will post other replies if I want to know more depending on your experience. Is this code correct
for that file: CODE <? $host="localhost"; $dbname="XXX";
$dbuser="XXX"; $dbpass="XXX";
$connection=mysql_connect($host, $dbuser, $dbpass) or
die(mysql_error()); mysql_select_db($dbname) or
die(mysql_error()); ?> Add your suggestions or i....
Question Regarding File Transfer!
FILE TRANSFER (4) Hi friends, I am looking for a secure and robust file transfer web service. I am handling a sales
force which is stationed at different locations and is frequently moving. They need to upload there
activity reports frequently to our servers. So I am looking for an easy to use secure and robust
file transfer web service which can be used by my sales force for their needs. Thanks & Warm
Regards. ....
I Want To Share With You
The best file hosting service (4) http://www.lobortis.com/about Lobortis enables users to upload files to our servers, and publish
the download links on the World Wide Web. User is allowed to upload only legal files which are
freely distributable. They allow 5 GB upload no server downtime Do any body know any other
best file hosting service Discuss....
Windows Ntfs Folder And File Compression. Good Or Bad?
(6) I believe everyone in this forum knows what a file system means and that every windows user knows
what FAT and NTFS means so I am not gonna start going into those. Well, the NTFS (Windows NT file
system) offers a few advantages over the good ol' FAT (File allocation table) file system one of
which is the files and folders compression. This I have done quite a number of times to save disc
space (and it really does save some disc space). i am using my computer as an example here. Consider
my 35GB partition which is carrying my Windows Vista Operating sys and has less ....
Hate Trying To Do File Sharing On Vista
(2) i've had this attempt before with no luck now i'm going to try again! now that i got my
two laptops (laptop1 - Vista, laptop2 - XP) wirelessly connected, i still can't see each
others shared files... i tried this before with my PC (XP) and laptop (Vista) now i have to make
this work because i have some files needed to be transfered between them... i have gone through
the manual process of anabling file sharing blah blah through here
http://www.microsoft.com/technet/network/e...e/vista_fp.mspx
http://www.home-network-help.com/simple-file-sharin....
Test Our New Free File Hosting! The Fastest In The World! Check It :)
(12) Another freebie guys, and it certainly rocks! /smile.gif" style="vertical-align:middle"
emoid=":)" border="0" alt="smile.gif" /> We launched the new Free File Hosting files-upload.com –
check the speed! Take out anything you like, no limitation at all. http://files-upload.com ....
Read File (.txt) On Another Website Using Jsp?
(3) in my jsp program,i need to read a file (.txt) on another website,how can i do this? thanks a lot.
shorten title ....
A Trap17 How-to Guide For Beginners
Something for those who can't get enough of the Trap17 Readme file (12) I am not entirely sure if this the right place to post about this, but here goes anyway... For
those who find themselves slightly (or considerably more than slightly) clueless about where to get
started after getting a hosting account, here is an user guide that might potentially help you
out. I wrote it out of three hours, so forgive me if it's clumsy, but I'm hoping that a few
people here may find it useful. Feedback is greatly appreciated /smile.gif"
style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> I'm planning to build on
a FAQ....
How To Open A .daa File
(36) Hi there, How do i have to open a file with extension .daa Somebody told me to copy it on cd and to
run it from cd rom but i got the same problems. What dp i need to do to ppen the file? Thanks....
Linux Question: Amarok And File Permissions
please help, i can't get it to work with all music files (4) hey, i use to use Linux DC++ to download music from some hubs and i usually download it to
/home/downloads/ and then i move the files to my collection on another HDD a sata one, on
sda3/music/ but when i move the files using krushader root mode they become posessed by root and
amarok can't play them displaying a locker on the file's icon. I tried to " chmod 774 music
", where music is my music directory, as root in konsole but no luck. What should i do to make a
whole directory accessible from amarok as user?....
How To Put Music In The Background Of A Powerpoint Presentation
without having the viewer download the music file (9) Well, i made this power poit presentation in memory of my grandfather as many of you kno, passed
away exactly a week ago....and i am trying to get this song to play as background music..and i did,
but there is one humongus problem... in order for the people who are viewing it to hear the
background music they have to download the music file as well ad the powerpoint presentation, which
on my DSL conntection taked almost 2 minutes, and i could just imagine what it will be for a dial-up
user (my grandma who wants to see it)... Some people may say, its impossible, but i kn....
Simple C File Handling In Action
Small code snipet which covers most of basic file handling and navigat (3) Yesterday I suddenly got a lot of work. The same work we try to push off, yes you are right all
formalities to get the code review incorporated and update all source code files with code review
headers. Imagine if you need to open 300 files one by one and append code review headers at the
end. Since most files are reviewed in groups of 20 to 30 files. We require one header to be placed
in say 20 to 30 files. To simplify I went back to my class assignment days and wrote this small c
utility to open all files passed on command line and open attach code review headers an....
How To: Make A Simple Php Site
Making one file show up on all pages using php (21) I have looked all over the site and could not find anything that was like this simple, or just like
this at all.. For some people i know that you are using a basic HTML site...and having a big menu
if you want to add somthing you have to go into every one of the pages and add or remove or edit
what you want to do, but with somthing verry simple all you would have to do is edit one file, and
all of the pages that have the PHP script on them would suddenly change to what that one file is.
So to start off if you are planning on using this little tirck, the page that you a....
How Do I Make A (video) File Smaller?
(11) Ok, I want to host a video that I have in my computer, but the problem is that the video is too
big, 790MB. My host can't handle a file that huge so I was wondering if there is any way I can
make the video file in my computer smaller? I don't want to mess up the video and make it
smaller, I was wondering if I can keep the current 790MB video that I already have but copy only
about 10MB of the video into a new file that I can use for hosting. Anyone know?....
Transfer File Of Any Size Using Winsock Control
Winsock Help (5) This tutorial shows how to transfer file of any size using winsock control. - Open VB; - Select
standard exe; - Press Ctrl + t to show the add component window; - Select winsock control and
microsoft common dialog; - Add one winsock control in the project; - Name it winsock1; - If you want
to add chat then add another winsock and name it winsock2; - Insert another winsock object if you
want to add chat also; - Add a microsoft common dialog box; - Name it cd; - We will use this
winsock1 object to transfer the file and winsock2 for chat; ------------- The basic idea : ....
Import From Excel File Into Mysql Database
(7) Has anyone tried using the excel import function that comes with phpmyadmin
http://www.phpmyadmin.net/home_page/ - it does not require any additional plug-ins or scripts and
is fairly straightforward to use. In phpmyadmin, if you click on the database table which you wish
to import the data to , there is a link on the bottom left corner which says "insert data from a
text file into the table" - although it says text file it still can be used to import an excel file.
When you click on this link you will be taken to a page where you will be asked for the file name
(the....
My File Manager Is Working
(2) I tried to change the html for my site in file manager but it just has the default page - the one
when you activate your site. /sad.gif' border='0' style='vertical-align:middle' alt='sad.gif' />
How do i change files?....
500 Mb Free File Host!
http://www.spread-it.com/ (18) Spread-It is a great, no nonsense file host. I've been looking extensively at free file hosts
and most are up to 100 mb or something along those lines. The bigger ones for some reason are
usually Japanese, but this a totally free, no registration file host for anything up to 500 mb. The
only catch is that if it's not donwloaded once in 14 days it get's deleted. But other than
that they claim it's hosted forever. http://www.spread-it.com/ ....
Looking for php, writes, txt, file
|
|
Searching Video's for php, writes, txt, file
|
advertisement
|
|