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




Editing A Line In A File


I have a php file, I need to open it, find the line that reads "$pass[0]  = "fa03eb688ad8aa1db593d33dabd89bad";" and edit the value
"fa03eb688ad8aa1db593d33dabd89bad". How can I do that, I have

   #Open the file
   $ourFileName = "access.php";
   $fh = fopen($ourFileName, 'r+') or die("Can't open file");
   fclose($fh);




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Editing One Line Of A File.
MySQL ahs been giving me tremendous problems ever since I tried to switch to version 5.0.20. I thought that I might make my own SQL program, out of PHP code.

But if a user of it has a table with hundreds or more entrys, editing one line would take hours. If you can't get PHP to edit one line with a few functions, what about splitting a file into three parts and then merging them together after editing the middle part, like so: Code:

Delete Entire Line In Text File If Anything In The Line Matches Search String
how would I code a php script that would open a text file, look for a string i specified, and if it finds that string, it will delete the entire line in the text file that contained that text. I'm new to php, so sorry if this is really obvious..

INI File Editing...
Does anybody know how to open up an ini file and edit one section?

like find the section called [votes] and just replace the values underneath it, in that section alone?

vote.ini
[votes]
a=7
b=2
c=55
d=0

find that section, replace the values with there new numbers, without having to deal with what sections come before and after this, in the ini file?

Php.ini File Editing
I need your knowledge,

I want to add to my website php.ini file to change the settings of my
mail() function so that my function is working fine except that the
sender email is not my user but nobody@hostingprovider.com so Someone
told me that its easily edited using php.ini but he dont know how, so
I thought that you could help me in this situation.

more details about my hosting:
- Linux host
- php 4.4.6
- apache

Editing An Xml File
I have an xml file that I use to store information in. I want to be able to add info to it without deleting whats in the file.

Open File, Add Line At Beginning, Remove Last Line
I'm trying to open a file, write one line at the very beginning, and delete the last line.

Right now I'm stuck at trying to open the file and write a line at the very beginning. Here's my code:

$f="myfile.txt";
fwrite(fopen($f,"a"),"Add This Line");

I know I'm opening this file in append mode, where it will always write my text at the end of the document, but I can't figure out any other mode that would allow me to open an existing document and not delete everything that is already in it.

Editing Info In A File
I am using a tab delimited file to provide information for a page to be displayed. I have used fgetcsv() to get information from the file, and it returns an array of information. I was wondering if there is a way I could change information in the file. For example lets say that $content[2] = "This" how could I change it so that, $content[2] = "That". I know how to change the variable to a different value, but I haven't figured out how to change the actual file.

Editing A (config) File
I have a file with some configation in it... I am wondering how I
correct single values in there.

The most secure is to recreate the file, then rename it.

But is there a way to correct a line in the text file?
setting1=bla -setting1=blablabla

Needless to say, there are things in there I'd like to keep at all
times.

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.

Editing And Overwritting Data In .txt File
I have a page whereby a text area is shown, and the initial value of it uses php to display the contents of the .txt file so that a user to update the paragraph of text shown and click submit to overwrite the .txt file with new information. The problem is i have no idea how to code it so that i can make the .txt file be over written. Code:

How Do I Read A File Line By Line Backwards?
I need to read a txt file backwords line by line.

Read The Whole Txt File Content Instead Of Line By Line
how to read the whole txt file content instead of using "fgets" and read line by line.

Read Text File Line By Line
I have been given a textfile which contains data on 1000 businesses.  Each line contains a name and a code which are seperated by a comma.  The code below allows me to display the entire textfile but I want to read in the values from each line and store these in a database.

$filename = "businesses.txt";
$fileToOpen = fopen($filename,"r");
$content = fread($fileToOpen, filesize($filename));
$content = nl2br($content);
fclose($fileToOpen);
echo($content);

Does anyone know how I can read the data in line by line so that I can store it in a database.

Read A File Line By Line
Is there a function to read a file line by line in PHP, i.e. the way you do in Perl like <file_handle> ..... Note that i don't want to use the file() function.. that read entire file into an array and is not suitable when you're reading large files.

Getting The Last Line Of A File
I am writing a script which needs to read the last line of a file. I don't want to read the whole file and then seprate the last line as some of the files will get pretty big.

Is there a function (Something like tail from unix) to let me do that? I tried searching the php site but didn't get far.

A New Line In Txt File.
I wrote a php script which can generate a report line by line. I did it by fopen function and create a new line by " ". Code :

New Line In A Txt File
I'm doing a script which insert text in a .txt file. eg,

$fp = fopen(sth.txt,'w');
$string = "text n";
fwrite($fp, $string);

The problem is that the n dosen't work!, how can I insert each line in a new line?

How To Add To The First Line Of A Txt File?
I'm trying edit a script called shoutbox and it simply just adds a name and comment to a txt file on a new line and includes it into my webpage via php.

My problem is that it adds the new comment to the bottom... I need it to add that comment to the top in a accending order.

$lines = file($file_path);
 
 $handle = file_connect($file_path, 'a');
 
 if(@fwrite($handle, $message['name']." | ".$message['url']." | ".$message['message']."")) {

I've tried w+  but it erases the previous comments added to the data.txt file.
Does anyone know how I would add a line to the top of the data.txt file without first erasing it?

Replace The Last Line Of File
I have a text file and I want to replace the last, and only the last of the file with some other text I store in a variable.

Removing A Line Within A File?
I have an include file (links.php) with nothing but links, the filenames are dates ( i.e. YYYYMMDD_hhmmss.php), all the links point to files within the same directory (i.e. /data). I read all these files in from the directory with readdir() and then build a form in order to remove certain files. I need to be able look into the include file, find the correct link, and remove it. I have been trying to use a foreach statement and preg_match() and printing back to the file lines that do not match and skipping the ones that do with absolutely no luck. It doesn't seem to match the link within the file.
Here is a snippet of code:

Rewrite File Line
I am trying to write a portion of the script that will replace a line with a new one in a text file. I figured fputs would do the trick, but I tried opening the file with fopen with the mode r, r+, and w+ and they don't seem to do the trick. r will only read, r+ is supposed to read and write, but instead it just reads (nothing new was inserted when I tried it), and w+ erases the file then inserts the new information.

The way the script works, it will search for the proper line using a while loop, once found, it will take the information and modify it slightly, then it's supposed to overwrite the new line over the old one, afterall, the pointer have not changed it's position since it found the correct line.

I don't want to replace an entire file because the script will do more work, just one frigging line in the same position.

How To Delete Last Line Of File
I have a flat file on the server which I append to from a HTML web form.
I need to delete the last line of the flat file before I append though.

How do i do that?

I have the following code. I'm not sure if it's correct.

$pattern = "</member>"; // what I want to look for.
$ora_books = preg_grep($pattern, file('/path/to/your/file.txt'));

Line Replacement Within A File
is there an easy way to take a file, and within that file, replace a line? I am taking a source text file, and appending to the end of the destination text file, and then in the destination text file, replacing certain lines of text with something else.

New Line On The Flat File
i recently decided to code an extreamly simple php cms which i can use on any websites i make. so far i have made an input form, a procesing page, a flat file, and an index with an explode function which shows the last 5 posts newest to oldest.

all of it works up to a point. the problem i have come accross is that when you fill in the message part of the form if you press enter to give a new paragraph it creates a new line on the flat file which the script then thinks is a new line of arrays which makes each new paragraph a new post adding it above its proper post.

i wonder if its possible to somehow stop the line break in the textarea counting as one in the flatfile.. or even better if i can replace it with a < br> tag so it shows as a new paragraph.

New Line In A Flat File?!?!
Made a simple script that can add, edit, or delete objects in a flat file. To use for news, simple ecom, etc. Created the script and tested in on one server and worked perfect. Just moved it to the actual server it will stay on and for some reason what used to make a new line for a new object just adds an upright looking rectangle looking symbol.

Sorry can't copy it here cause it won't show up; will only show up in notepad. Once the symbol is added it will add the new data in the same line is the last object in the flat file. Anyone have any thoughts?!?!?! 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.

Finding A Line In A File
How would I write some php code that opens up a text file, looks for a specific line, and delete it?

Basically I have a text file called photoList.txt, which has a list of all the photos stored, one line at a time. And if I want to delete the photo, I basially have to delete it from photoList.txt.

Moving To New Line When Writing Out A File
What I'm trying to do is insert a new category into a array then write the array out to a file. This works, however, the text file uses carrage returns to seperate the items of the array.

For example:

cat1
cat2
cat3

What happens when I write the file is:

cat1
newCatcat2
cat3

(assuming that newCat is sorted between 1 and 2)

What I want is to have the next item in the array pushed to the next line, but I have not been able to do this.

here's my code:

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?

Writing To A File And Not Having To Do An Fputs For Each Line
I'm trying to output HTML files with php. I have read that in order
to do this, I have to preface each line with something likes;

fputs($filepointer, "the line that I want");

I want it to just spit out text that is already in paragraphs and junk with all of the HTML Code.

Is there a way to do it the same way I predeclare printing with
print <<<ENDTAG
yadda
ENDTAG;

How can I do something like that only I am printing to create a file
without fputs for each $#!! line?

How To Edit A Line In A Text File
i have a text file (just testing php) which stores about 10 lines where each line represents a user request. how do i edit that line to allow the user to edit the $bookwanted ? the lines below shows my display info for the user.

$file=file('logindata.txt');

foreach($file as $line){
list($bookwanted,,$user,$pass,$acct,$email,$amt,$date)=explode('|',$line);

if (($username == $user) && ($password == $pass) ) {

// display info for that particular user

}

Reading A Line At A Time From A File
Just wondering what the best way to do this is?

What i specifically want to do is check if a user exists on a unix machine.
The best way i was told was to read a line at a time of /etc/passwd and
check if the username is in that line.

Line Breaks When Reading A File
Consider the code:

$arrText = file ("http://www.site.com/page.htm");
for ($i=0; $i<count($arrText); i++) {
echo("$arrText[$i]
");
}

(I did not test the snippet for errors)

The line breaks appear to be different from the original .htm file. Why?

Reading One Line At A Time From A File
is there a way of which I can read one line at a time from a file?

Reading A Single Line From A File
In asp I can read a text file line by line like this.

<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("FileName.txt"), 1)
strLine1 = (f.ReadLine)
strLine2 = (f.ReadLine)
strLine3 = (f.ReadLine)
f.Close
Set f=Nothing
Set fs=Nothing
%>

I need to assign line 1 to one variable line 2 to a different variable and so on. Any help is greatly appreciated. Btw, I'm using php4.

How To Access A Single Line From A File
I want to select a single line from a file. How can I select a line from the file and save it in a variable.

Random Line From Text File
I want to grab a random line from a flat file and then echo it. I could probably do this but the alcohol prevents me from thinking.

Skip First Line When Parsing An Xml File
I have an xml file which I cant change, the problem is that the
first line looks like this <?xml version="1.0" ?> with the rest of
the xml being fine. However when I try to parse this I am getting a
malformed xml error. THis line was added recently, the parser worked
before. My question is how can I get rid of this first line in the
xml file - which I get from an internet feed using
fopen("http://dsfsf.com/sdf.xml", r);

Read Line From Text File
I have a text file that i would like to use PHP to read from. each line
ends with a. I need to read from the beginning of the line, only upto that:

right now i'm using this, which is sloppy and slow:

if ($chr = fgetc($file)) != "") { }

which of course reads in one byte at a time till the end of line. is there
a better way?

Replace A Line In A Text File
I would like to replace a single line in a text file. The initially i only had to have a single line so I could just use fputs to rewrite the entire file.  Now I have three lines and want to selectively replace one of them..

Detect Line From Text File
I have a text file that list out several activation code
aaaaa1
aaaaa2
aaaaa3
aaaaa4
aaaaa5
Then I will create a form which user will enter the line number of the text file to get the activation code. Eg user enter '2', so the system will pop out 'aaaaa2'.

The Problem is I really stuck on how to get php call the line number in the text file.

Modifying First Line Of Uploaded File
Here is what my script does, you select a .csv or file that follows those guildlines. Script then loads it into mySQL database using the first line as a reference to which field each row of the .csv (spreadsheet) goes into. One problem: some of the first line references have spaces in them. Since MySQL doesn't support spaces I need to take that first line and change them all: example

WORK ORDER,CUSTOMER NAME,CUSTOMER ADDRESS needs to become WORK_ORDER,CUSTOMER_NAME,CUSTOMER_ADDRESS

....is there a ways to do this? I know I'll probably have to upload the file first, before I can modify that first line. I cannot replace that first line with a specific text, since the order of the fields change sometimes.

Printing The Line Number And Name Of Included File
Does anyone know how to echo the line number and included file name in php.

I like to use development tags but sometimes I forget what included file they are in and what line they are on. I use a master variable to turn off all of the dev tags, but I would really like an easy way to automatically print the line number and file where the function is.

This would be like if there was an error, but with out breaking the script and with out generating a nasty error.

Reading Strings In Text File (1 Per Line)
I am trying to take a text file containing a list of email addresses (1 per line), and insert each line as a new item in mySQL.

I know how to do most of the php and the mySQL, but I am not sure about the syntax of the line to return the string from "line x" of the tex tfile.

From the php doc. I have this code to read the full contents of my text file:

// get contents of a file into a string
$filename = "/usr/local/something.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);

My question, clearly is:
then how do I split $contents into an array so that $emails[150] could return the email number 150?

Deleting A Line Of Text From A Txt File From A Form
How can i delete a line of text from a .txt file using a form?

because i have a form right now that saves information from a form to a txt file for news, now i need to know how to make it so i can delete it from a form.

also, if you know how, how do you overwrite lines of text in txt files from a form?

Search File For Line And Replace With Update
I am trying to search through a file for a line. My line that I will be searching is in a cron flat file. I need to search that file for a line simirlar to:

59 23 * * * wget -q http://www.site.com/runPage.php?usr=name

When the line is found, I need to make changes to it. I have read the file into a variable with fread, is that the best way to get this information for the type of search and replace I am trying to do?

From what I have read in past posts, it seems like strstr is a quick way to go or would strpos be? Or, do I have to do more than that?

Blank Line At Beginning Of Downloaded File
I'm sending a file to a user with the following code:

header( "Content-Type: application/binary");
header( "Content-disposition: attachment; filename=$filename");
header( "Content-Transfer-Encoding: binary" );
passthru( "svnadmin dump ".$svn_repos_loc."/".$name );

(the svnadmin dump command returns a mostly ascii file, but could also
contain some non-ascii parts)

Somehow the file that is saved on the recipients computer gets an
additional blank first line. Off course I can strip this somehow, but
I'm interested in an explanation of this behavior and I would like a
more appropriate solution!

Appending Text To A File, Starting A New Line.
Im appending text to a file. And I'd like each 'append' would start on a new line of a file. I tried 'n'. but it doesnt work. here is my code:

$fp = fopen("$filename", "a");
for ($i = 0; $i < count($arrText); $i++){
fputs($fp, $arrText[$i]);
} fclose($fp);

note: one of the array $arrText, eg. $arrText[3] = "line 3" . "n";
the next array $arrText[4] will NOT start on a new line, it will just joint the rrText[3].

How Do You Create A New Line Each Time A File Is Written To?
I am trying to write user submitted information to a file, and I am having a little problem. Here is my code:

<?php
import_request_variables($_POST, "FirstName");
$file=(/fname.dat');
$f=fopen($file,'a');
fwrite($f,$FirstName);
fclose($f);?>

Each time the file gets written to, the info is just tacked right after the last character from the previous entry. How can I get this to write each entry on a seperate line?


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