Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Add Something To A Text File?


How would I go about adding a string on a new line at the end of a text file?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Read And Display Japanese Text From Text File
I posted a question regarding reading japanese
text from a text file.

Well, since I solved the problem, I thought I'd post my solution for
the benefit of other people with the same problem.

The plan was to make a script to read and display japanese text. I
will use it for making a japanese proverb script and for a japanese
language study script.

Method :

I wrote a simple kanji text file (saved with UTF-8 encoding)
I wrote a simple PHP script to display the file contents (saved with
UTF-8
encoding)
I specified the content-type header for the HTML page :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

*** All files have the same encoding. ***

UTF-8 supports japanese characters.

and it works!

this is my PHP (and HTML) script :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP : Japanese Text File Read : Exercise 1</title>
</head>
<body>

<?php

$filename="japanese.txt";
//open file
$fp = fopen($filename,'r');

//loop through each line in the file
while($line=fgets($fp))
{
//output current text file line
print $line."<br>";
}
//close file handle
fclose($fp);

?>

</body>
</html>

I know it's a very simple script, for testing purposes only. It
displays the contents of the japanese text file line by line.

The key was to save all files in the same encoding (I used UTF-8) and
to specify the encoding / charset in the HTML header (<meta
http-equiv="Content-Type" content="text/html; charset=utf-8">)

Remove Text Header In Text File
I have been having trouble removeing two header lines at the top of my txt file. You will see in my code the different things I have tried but with no luck. Below I posted my script and data. I am doing a few other things in my script as you will notice but this is the only thing I am having troble with. Code:

Text Box To .txt File
does anyone know how to make a text box in php that when submitted, it writes to a .txt file?

Text File Display
I have a number of SQL reports that create standard 132 column text files. The user wishes to view these files in a browser in addition to their daily printing on a laser printer.

I can handle directory structure, etc with PHP but I would like to know what is the best way of displaying these text files on screen. We can select them but they are very plain. Is there a TXT2HTML ot TXT2XML type tool that can display headings, bolding, etc without too much difficulty. I would rather not reprogram the reports as there are hundreds of them, and embedding HTML would not be an answer as they need to be printed on a regular laser.

Saving To A Text File.
I haven't been able to find a way to save the results of a MYsql query into a tab delimited text file... Anyone know how to do this, or if there are any already written scripts out there that perform this, or a similar function?

Database Row To Text File
I need to get the contents of a MySQL database field into a text file, and write the file to the server. I can not seem to get any filesystem functions to work, because it tells me I do not have permission to do anything. I am on virtual hosting, so it seems easier for me to try to FTP files to my own server.

Perhaps you guys can give me some pointers, this is kind of the idea I am running on:

Writing To A Text File
i have a text file with the number 250 in it and nothing else. i have a variable which is worth a 300. How can i add this value to the one in the file so that the value of the file has changed to 550?

Get The Last Word From A Text File
i have a text file that's update all the time. i need to get the last word from it. how can i do that?

Write To A Text File Once Only
I've got a script that writes to a text file:

Text File Into Variable
I'm setting up an script that will send mail to an address given by a user. The problem is that the body of the e-mail varies depending on a few responses that the person gives, and writing out like 1000 lines of code just to get each of the outcomes covered is not my idea of fun. My question is, is there any way to make a variable in PHP the contents of a .txt file so I don't have to have that big of a script?

Retrieval From A Text File
How would I go about retrieving info from a text file into a variable field? If the data is stored in more than one line or separated by line breaks?

Php File Showing As Text
I have tried to upload a tested PHP file to my server and every time it gets
accessed it displays itself as text and does nothing that its supposed
to...

Form To Text File
I don't know anything about PHP, ASP, CGI, all I can do is use Microsoft FrontPage to edit html. But I have been searching the internet for a script (any laguage) that can send an html form to a text file. But I need the new data to replace existing data in the text file every time I submit new information.

Is this possible in PHP or any other language? I’m hosted on a UNIX server with php installed and I have access to my cgi-bin and all I need is this little script to complete my website.

Str_replace From Text File
I want to use a text file with words that needs to be replace. $theentry = str_replace(array('word1', 'word2'), '*****', $theentry); Instead of array('word1'),'word2') i want textfile.txt to be opened with all the words to be replace with ******.

Text File Instead Of Database?
Does anyone know a script that I can use to manage members of my website (preferably with a control panel-type interface) but without using a database? I read on hotscripts.com of one that uses text files instead, but the link says that the site is no longer offering that file.

If someone could help me it would be great, as I know nothing about scripting. By control panel, I mean a page that I can go to on my site (not open to the public) that I can use to Admin the users. I would like it to go something like this: (this is what was offered at hotscripts.com)

New Members Username:
New Members Password:
New Members Name:
New Members E-Mail Address:

And optionally (I don't really need it, but if its possible, hey why not) a place for me to put in an admin username and pass to get into the page mentioned above. I would also like to be able to implement this script on my main page (see here for what I mean.

Exploding Text File....
I want to put a text file into a form field, and then submit it to a page that will split up the text file on two criteria and then loop through each split result inserting new db records. A sample text file would be:

question 1;option1;option2l;option3

question 2;option1;option2l;option3

question 3;option1;option2l;option3

I need to split it on blank lines and then again on the options so that my insert would be insert questionname, option1, option 2....into questions. Can someone help please. I know I can use explode, but unless I am missing something then its just not working for me.

Get Data From Text File
I am trying to do is display the date like so: PHP Code:

Deleteing From A Text File?
Is there a function that deletes a line from a text file?

Exporting From Db To Text File
I have the following sql statement that works from phpmyadmin and from the MySQL command line, but not php. The resultant $sql variable is the following:

$sql=select logrecno, county, sumlev
into outfile "/tmp/census.txt"
fields terminated by ','
lines terminated by ""
from sf1_msageo
where sf1_msageo.county=97 and sf1_msageo.sumlev=140

$result=mysql_query($sql); The query executes, returns no messages, and does not create a file. Any idea as to what I'm doing wrong?

Get Date From Text/php-file
I'm new to PHP, and i want to create a pop-up (on page load) on certain dates..
What i have is the script for the pop-up:

<body scroll="auto" <?php $today =date("d-F"); if ($today==$datum)
{echo "onLoad=".$g_birthday_pop;}?>>

The pop-script =
$g_birthday_pop = <<<EOT
"MM_openBrWindow('http://www.nu.nl','popup','width=300,height=300')"
EOT;

$datum is in another file (include/datum.php):
<?php
$datum= "30-December";
?>

And this works if the date is 30th of December,
but i want it too on other dates that you put in $datum
Something like:
<?php
$datum= "30-December";"10-March";
?>
So i want to control the pop-up just by editing the "datum.php"-file

Comparing A Text File
I was wondering if this is possible: Compare a row from a table to a row from a text file, and if that row is not in that text file, then delete it from that table, and move it to another one. Say for example I read in a text file and assign the following variables: PHP Code:

Search A Text File
I have a text file that each line is an array, I think. I looks like this

name | id | # | # | # | total
name | id | # | # | # | total

and so on...

I would like to seach the file by "id" and only display the line with the particular "id".
I also think that the bit size of each line will change from line to line, so I don't think that I can put in a static number to search to the end of. I thought about using fseek(), is that the best way to go.

Php Generate Text File
I have been trying for the past 3-4 days now to get flash to write into a text file for me. Basically I made a rating script on flash and then I made another php file that counted the top 10. I want to get the info from the top 10 to a text file but I've been stuck for a while now.

I read php.net for the commands, kessler's tutorial, but I'm just missing something. I posted the top 10 script that works and the other that doesn't work when I try to text can someone please tell me what I'm messing up on? PHP Code:

Get Date From Text/php-file
I got it going.
Now i have another question;

Is there a way to link a date to a persons name,
so i can get the pop-up, and the pop-up
then automatically grabs the right name, and displays it?


Text File Behavior
I have a question about the behavior of a text file thats being written and
read to.

Say Im using an XML file as the database for my little application. Users
come to my site and the file is read and parsed and coverted to some display
in html. On another page users can add information that updates this XML
file.

Is there any risk in this approach? While the XML file is being written to,
what is its readabililty? And vise-versa. Assuming Im using the standard
read write functions for files in PHP, will the read wait for a write to
finish, etc.

Edit Text In A Txt File
here is the php code!

i am trying to use to 'edit' hyperlink to edit txt in member.txt.
Problem is that it reads the values ok into an array, however when i
attempt and update new values into the file, i get no results. Does
anybody know where i am going wrong????

<? session_start();
// Set updated content for user

if(!isset($_POST[Submit]))
{
// read content from file and place into array, this is used to put
initial content into form
$fc=file("../username/member.txt");
$userid_no = $_GET['record_id'];
$line = split("|",$fc[$userid_no]);
$user_id = $line[0];
$password = $line[1];
$firstname = $line[2];
$lastname = $line[3];
$email = $line[4];

}
else
{
if(isset($_GET['record_id']))
{
// build record into string from post values
$update = $_POST['user_id'];
$update .= "|";
$update .= $_POST['password'];
$update .= "|";
$update .= $_POST['lastname'];
$update .= "|";
$update .= $_POST['firstname'];
$update .= "|";
$update .= $_POST['email'];
$update .= "|";
$update .= "";
$update .= "|";
$update .= "2";

Write To Text File
I have a form which takes user input. On submit, the form will run a
php script that will create a new text file using the user input.

I want this text file to popup or open in a new page. The problem is
that when the page opens it still shows the old text file, i need to
hit refresh for it to show the last user input.

the html file (greatly simplified):
<html><head>
<title>Untitled</title>
</head>
<body>
<form action="action.php" method="post">
<p>Title: <input type="text" name="Title" /></p>
<p><input type="submit" /></p>
</form>
</body>
</html>

The php file (simplified as well):
<?php

$spot_code = $_POST['Title'];

// Open the file and erase the contents if any
$fp = fopen("myfile.3dml", "w");

fwrite($fp, "<TITLE NAME=" . '"'. $spot_code .'"'. " />
");

fclose($fp);

//redirect
header( 'Location: http://localhost/mytest/myfile.html' );

?>

the text file, myfile.3dml is embedded in myfile.html (it requires a
plugin to view - it's a 3D world). When myfile.html is opened it
displays myfile.3dml but it needs to be refreshed to show the current
input.

Searching A Text File
I want to be able to search for text in a text file. For example if there was this in a text file:

php1:mysql1
php2:mysql2
php3:mysql3
php4:mysql4
apple:orange
php5:mysql5
php6:mysql6
php7:mysql7
php8:mysql8
php9:mysql9

I want to be able to search for the word "apple" and then echo what is next to it, which would be "orange". How would I go about doing this? Also, if I were to search through these files in php daily with a lot of people searching through them, would my text files become corrupt?

Parsing Text File
I'm working with a text file that contains the names of websites and their corresponding URLs in the following fashion: <a href="www.cnn.com">CNN News</a>
Each site and title is separated by line breaks. I'm not very experienced with fopen, fread, etc. and was wondering if anyone could give me pointers on how to go about reading the text file line by line and saving the URL and title in separate columns in a database.

Oh, and one more thing. The categories of these sites are also included every so often. I was hoping to save the category in a third field. Ex:

News ( new line here)
<a href="www.cnn.com">CNN News</a> ()
<a href="www.bbc.com">BBC News </a> etc.

Trying To Modify A Text File.
What I need to do is to look at each line in the text file, find the userid that an administrator inputs into a form, and delete that line so that a new line can be appended with updated info.  Or, if anyone knows of an easier way to modify info on a certain line in a text file, I'm all ears.

Write To Text File
function Save_Data($word) {
$fp = fopen("search_strings.txt", "w");
fwrite($fp, $word);
fclose($fp);
}

I'm trying to keep a list of keywords. Everytime i open the file to check it, it only has 1 word in it. it keeps overwriting the previous word. How do i kee a proper list of words?

Edit Text File
I am trying to find a specific line, which starts with a unique word, then delete that line in the .txt file then rewrite that line. Code:

New Line In Text File
I'm trying to create a text file in php to generate a playlist. The problem is that I cannot manage to create a new line in the text file. Using /n still places text in the same line and just inserts a symbol to indicate the 'new line'. Using

just works when viewing the document in HTML (which is not what i need in this case). But what I want is to physically insert a new line in the text file so that when i open the generated file using notepad i see that there are actually new lines in the document and so that the playlist can be read normally with a music player.

Updating A Text File
I am currently building a PHP app, and some of the configuration is stored in a 'config.php' file which is created during the install. After install I would like for the users to update these values separately. for example:

line 5 of config.php is:
$language = 'english';

and this may need updating from the admin screen (using results from a drop down list of languages), without touching the rest of the file. Is there any way to locate and update a single line of the config file in my php script?

Putting Text Into A File
This code is supposed to create a file and insert some text into it. I had it working, but the file was not being put in the right place, so when I went to change it, this is what I got, and it doesn't put it there. Code:

[PHP] Reading A Text File Into A Dbase
I want to update my mysql database with a single text file (one table). Every row in the file is a new entry into the table but a row has several fields in it and that's where i have a problem. I'm able to load the file into an array and then insert it into the database but i have to split the row into different fields like: field1, field2, field3. I can't get it done. Can somebody help me .

Writing To A Text File On Another Server
I've a form on one server, which posts its contents to a PHP script that tries to write one of the fields to a text file on another server.

When testing this, when I try to write to a text file on the SAME server, everything's fine, it writes successfully.

However, it doesn't work when trying to write to a remote file, and doesn't even throw up any errors.

Here's the code:

$fp = fopen( "http://server.server.com/server/textfile.txt", "a" ) or die ("Couldn't open");
flock( $fp, 2 ); // exclusive lock
fwrite( $fp, "$email
" ) or die ("Couldn't write");
flock( $fp, 1 ); // release the lock

fclose( $fp );

Does anyone know why it's not working?!? Please help me!!!

Open A Text File And Put Into Array
I want to open the text file and put it into an array so i can search the contents of the text file.I've figured out how to search an array but cant seem to open a file into an array and then search it. I want to take blah.txt open it insert it into $some array
and then use the array_search function to search for the word the user puts into a form.If you can point me to a tutorial, that would be helpfull.This whole search thing is driving me nuts.Opening and writing to files is easy...now searching the files im writing to ??I'm lost.

Format Text File After Fopen
I use “fopen” to access the text file (this is working fine). Then I want to format the results. I tried “fgets” but there is a “return” after each entry in the text file. "fgets" thinks this is a new record and puts the data on the next line. How can I bypass the "returns" and use the file as is.

Example of the text file:

Sold_To_Name............: XXXX XXXX
Ship_To_Name............: ZZZZZZZZZ
Sold_To_Address.........: XXXX XXXX
Ship_To_Address.........: ZZZZZZZZZ
Sold_To_City............: XXXXX
Ship_To_City............: ZZZZZZZ
Sold_To_State...........: XX
Sold_To_Zip.............: XXXXX
Ship_To_State...........: ZZ
Ship_To_Zip.............: ZZZZZ
Sold_To_Phone_Number....: XXXXXXXXXX
Ship_To_Phone_Number....: ZZZZZZZZZZ

This is how I would like to format text:
Sold to
XXXX XXXX
XXXX XXXX
XXXXX XX XXXXX

XXX-XXX-XXXX

Ship to
ZZZZZZZZZ
ZZZZZZZZZ
ZZZZZZZ ZZ ZZZZZ
ZZZ-ZZZ-ZZZZ


This my current programing:

Search And Replace In Text File
I have a text file with 30 or so lines. Each line has this format:

sometext somevalue. They are separated by a single space.

I want to search in the file for "sometext" and replace "somevalue" with a particular string.

Export Mysql To Text File Via PHP
I need help on how to export one of table mysql to text file to download. (not saving text into server)
something with like header("Content-type: text/plain");

How Can A Line Be Deleted From A Text File
Since, I cannot seem to delete the last line in a text database using the code below.

What other way can I delete a line from a text file?

Making A Text File Value Into A Variable
I have a text file called data.txt that has one line of data with a number in it e.g. 500, basically i need a code that will read the first line of data.txt and store it as a variable e.g. $data = data and + 1 to the actual data.txt file. so this way the data.txt becomes 501 but the variable for the user is 500. Its just like a counter.

Editing Text File With A PHP Form
I am trying to do something with PHP that i am sure is pretty easy. But not sure myself how to do it.

I have a file that i want to pull into a simple HTML Form text field. From that field the person can just add in content or remove content.. Click "Update" .. And it will write the new content out.. Overwriting the old file if need be.

Split Up Text File By Keyword...
Does anyone know how to split up a text file by a key word in a while loop?
I have a 300k file that has 350 office names and each time I get to a new office name, i want to insert all of the text into a mysql column/table.

I receive a report every morning with the status of 350 different offices and would like to email each office their status.

I have used different varaiations of explode(), split(),fopen(),

file(), fseek(), exec(), array(), fread(), join(), and a few others, and i can not seem to get it right.

Writing Records To Text File
I have the following code which displays some some formatted text in my
browser. The problem is I need to create a text file and write the records
from this array into it. Does anyone know how to acheive this...

Question Re Writing To A Text File
I am attempting to code a small script to process the fields from a form
and write it to a text file using the semi-colon as the delimiter. So
far I am successful in doing that using the following:

$incoming_fields = array_keys($_POST);
$incoming_values = array_values($_POST);

for ($i = 0; $i < count($incoming_fields); $i++) {

$fp = fopen("formresults.txt", "a");
fwrite($fp,stripslashes("$incoming_values[$i];"));
fclose($fp);
}

But what I am encountering difficulty in is putting a line break (
) at the end of only the final entry so that the data from each form
submission is on a separate line.

Cant Write To A Text File On Godaddy!
i even created a file with all the permissions and plopped it on the server and its still not writable. anyone have this issues? and how did you get around it?

Form Post To Text File
I have a form that posts to my php file which in turn writes to a text file. The way I'm doing is probably far from efficient or the right way, but it's the first thing i've ever written and I have to get it done.
The way it writes now is it just puts all the form input next to each other in a text file. I want each field to be delimited or on new line so I can read it easily. Here's a snippet of my code:

<?php>
$filename = 'orders.txt'
$fp = fopen($filename, "a");

$string4 = $_POST["email"];
$string5 = $_POST["street1"];
$string6 = $_POST["street2"];

$write = fputs($fp, $string4);
$write = fputs($fp, $string5);
$write = fputs($fp, $string6);

fclose($fp);?>


Copyright © 2005-08 www.BigResource.com, All rights reserved