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


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Delete First 9 Lines In Text File


how I can delete the first 9 lines in a text file?




View Complete Forum Thread with Replies

Related Forum Messages:
Delete Lines From File:
How to delete $n first lines from $str if i know how much lines shuld remain in the string?

$str = "aaaaaaaaa
bbbbbbbb
ccccccccc
ddddddddd
...
zzz";

Can it be done easly with preg_replace? (i.e without splitting it by '', removing elements from array and joining tham back.

View Replies !
Delete Lines From A File
Can someone show how I open a file and delete everything in it except for the last 20 lines.

View Replies !
How To Delete N Lines From The Top Of A File?
I'm not sure how to do this in php - need to calculate and delete an unspecified
number of lines from the *top* of a file.

<?php
//append $visitor to the bottom of $visdata
$fp = fopen($visdata,"a");
fwrite($fp, "
".$visitor;)
//count the lines in $visdata
$lines = count($visdata);
if $lines > 10
{
//delete as many lines off the top as necessary
//to end up with 10 lines total in $visdata
}
fclose($fp);
?>

View Replies !
Read A Text File Where Contents Are Going Over 2 Lines
I have this code to read the contents of a text file: PHP Code:

View Replies !
Using PHP, To Add/subtract Lines Of Text To A Flat File (xml)?
Is it possible, using PHP, to add/subtract lines of text to a flat file (xml)?

I understand I can use PHP "file write" to create a file, and "append" to add to it - but is there a way to then remove a certain line from it?

I understand this is sort of a content-management issue, but basically I want to give users the ability to manage (add/remove) songs in there XML playlist.

View Replies !
Multiple Random Lines From Text File
I have a text file with HTML fragments, one on each line. I want to display 4 of these lines, in a random order, with no repetition. Code:

View Replies !
Extract Lines From A Large Text File
I need to get Line 120 to Line 140 of a hypothetical 300MB text file,

$lines = file('textfile.txt');

That will effectively load the whole file and parse them as lines array for me to.

extract line 120 -140 easily.

Now that is of course a really inefficient way. If you are unlucky, you might get banned by your webhost for being a nuisance. Is there a way to move the file pointer to line 120 and read 20 lines from there instead of the inefficient way? Can we use FSEEK.

View Replies !
Deleting Lines From Top Of A Large Open Text File
I am splitting up one huge text file in several smaller files to prepare them for database processing. So far I tested it with files up to 100MB and everything works fine.

Now here's my question: To optimize my script I would like to incrementally remove all lines form the original file which have already been copied to the smaller file.
This would speed up reading the original file in each loop.

Unfortunatelly I couldn't find a way to remove/delete lines from an open file. Of course I could read the whole file, delete the lines and then write it back. But for files bigger than 1 GB this doesn't seem to be a good idea....

View Replies !
Writing Multiple Lines Of Info To A Text File
when i uploaded my first .php file to my server it just displayed all the code and did not work. so i searched google for my problem and a guy said to save my file as a .php3 this worked but i am wondering if there is any other way to fix it. and if someone could tell me the difference between a .php and a .php3 file. Code:

View Replies !
Php Script To Filter A Text File And Extract Lines Starting With Keyword?
For a class, students are going to run an experiment on line. Each time
a subject runs, his/her data is appended to one giant text file. Their
own data set will be just one line starting with the keyword they gave
as identification.

The faculty does not want the students to be able to download and see
the giant data file. He wants the students to only download and see the
data that starts with their own identification tag.

in unix, filtering a file to keep only the line starting with code MCB
would look something like
tail -f your_file_name | grep MCB
from what I read.

Given the concerns the faculty has for protecting the database, what do
I need to look into to write a php script that would access the data
file, but only show a web page with the data corresponding to the
students identification code?

View Replies !
Delete First Line Of A Text File
how i can open a data.txt file and remove the first line and then save it.

View Replies !
Check ' In Text File And Delete
I have 6 document files and some file has ' each line in text about 1000 lines. I want to clear all ' each line and I save all files same folder, how should I do?

View Replies !
How To Delete Single Email Adres From Text File
I have a textfile:

bla@domain.com
blabla@domain2.com
haha@domain.com
la@domain3.com
zaza@domain4.com

How can I delete a single email from that text file ? E.g. I want to delete blabla@domain2.com so that the textfile will be:

bla@domain.com
haha@domain.com
la@domain3.com
zaza@domain4.com

How can this be done ??

View Replies !
Blank Lines Between Lines Of Text
how do i put a blank line between lines of text on my webpage using php

eg within my while loop

printf("<a href="%s?id=%s">%s %s %s %s </a><br>
",$PHP_SELF,$myrow["id"], $myrow["first"], $myrow["last"], $myrow["email"],$myrow["details"]);

printf("");//this is what i thought might workdoes not work.

View Replies !
Delete New Lines
I would like to delete the new lines, I mean the, so Itried this:
str_replace($row['facts_conten t'], &quot;
&quot;, &quot;&quot;) ;
But the new lines are still there, how can I do?

View Replies !
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..

View Replies !
Confining Text From DB To 5 Lines
Basically I have an article in a Database and I would like it to display in an HTML table but I only want it to show up to 5 lines. I'm not sure how I can accomplish this.

View Replies !
Cancel A Text Lines
I have a solution to cancel an line entrie within a table.

<a href="pa.php?loeschen=1&nr=$nr>

It works with reading or selecting text files and so I know if someone
has canceled a line.

But I don't know why it doesn't work with Apache because my solution
was with ISS. So my question what is another solution to cancel
particularized lines or what have I done wrong.

The variables 'loeschen' used to be not reconize, as
well(isset(loeschen)).

View Replies !
Reversing The Order Of Lines Of Text
So my problem involves the user submitting a single string of text. lets say that the page is a certain width, and the string takes up a few lines... for example:

the user enters "this text takes up more than one line because it is long"

and the output is:

this text takes
up more than one
line because it is long

how can i make it look like this, with the lines reversed: Code:

View Replies !
Multiple Lines Of Text Over An Image
I've been attempting to work with the following code to generate a background image with text on it that includes a user's name, email address, and other pertinant information. However, I can't figure out how to get the code to allow multiple lines of text. The code I'm using is here : Code:

View Replies !
Separating Lines Of A Text Field
How would I go about splitting:

John Doe

Denver

Colorado

Into separate variables for each line so that I can plug them into a form?

View Replies !
Plot Graphic Lines And Text Dynamically
I'm looking for a method to plot graphic lines and text for a bracket-like
display with multiple tiers in a browser. I'm familiar with GD for
outputting dynamic graphics, but have never utilized its native drawing
capabilities. Is it well-suited for this task? Any better alternatives?

View Replies !
Q: Extract Only Text Lines Visible In Webbrowser?
I need to web query for further processing, f.ex

http://moneycentral.msn.com/investo...YMBOL=F,MSFT,DE

I use

<?php
$MSN="http://moneycentral.msn.com/investor/external/excel/quotes.asp?SYMBOL=";
$QSymbols="F,MSFT,DE";
$QStr="$MSN"."$QSymbols";
$lines = file ($QStr);
?>

However, the relevant information is only 3 lines on the webpage, but
more than 1000 lines in $lines, so it is slow and tedious to work
with. Is there any way to extract only the lines visible in the
browser?

View Replies !
Creating An Image With Multiple Text Lines / Wordwrap Using Imagettftext
I am in the process of creaing my first image using the GD library and imagettftext.  I have got so far, but now hit a stumbling block. The process is as follows...

User answers choices to create the text of a letter. Letter variables added to image?get
Image called from page.

I have got it all working fine apart from getting text to start on newlines when it reaches the end of a section. Code:

View Replies !
Open File, Put First 5 Lines Into A Variable, Close File...
1) I want to open a file on my server.
2) I want to read only the first 5 lines.
3) Put the first five lines into a variable.
4) Close the file.
5) Display the contents of the variable.

I know how to use the fopen() but I have big problems just trying to read the first 5 lines only? I tried many things. I downloaded some search scripts which displayed the <meta> tag only from html pages...

What is this guy doing?

Well I have a big site and content is added and changed everyday. I have a dynamic page that reads a directory for files and then puts a link (well it includes the file for reading on my php page). That works great! MY PROBLEM is that I want not only a link but a small description below it (basically the first five lines on the file)...

See so far:
Quote: if (isset ($content)) {
include ("files/$content.html");
echo "<p><A HREF="read.php"><b>Back to index</b></A>";
} else {
echo "<b>Opening directory, reading files, and listing them as a link</b><p>";
$handle = opendir('./files');
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo eregi_replace (".html", "", "<A HREF="read.php?content=$file">$file</a><p>");
}
}
closedir($handle);
}

View Replies !
How To Delete Only Certain Text In A Mysql Row?
I have a table setup that has a column setup as friends and users can add friends to this column no problem.

What I would like to know is how to delete only certain parts of the text of the row/cell where their friends are stored.

The friends text is seperated by the following :

" , "

That is a space on either side and comma in the middle of the space.

I know how to explode the results and put into an array to display the reuslts, but is there a way to delete only one of the friends if the text is as follows.

 , thomas , frank , irene ,

I think you can get the idea.

Is it possible to do this or should I just update the whole cell without the array[$i] result being the friend?

View Replies !
Delete Text In Inputboxes
I fill out an inputbox and press submit, when I press back or even reload in firefox, the inputboxes continue to have the same values filled out previously.

View Replies !
File Lines
tell me how i can include the last 10 lines of a file on a page with php and how i can include line 4 to 20 with php and how i can include a random file.

View Replies !
Delete Function That Deletes A String Of Text
I am trying to fix my delete function that deletes a string of text that may or may not have single, double quotes, pound signs etc.

function delete_bm($user, $url)
{
// delete one text string from the database NOT a url as would be suggested
if (!($conn = db_connect()))
return false;

// delete the Item
if (!mysql_query( "delete from XMAS_WISH_LIST
where username='$user' and XMAS_ITEM='".mysql_escape_string($url)."'"))
return false;
return true;
}

When I run this on my web page, I don't get an error, it just does not delete the item that I am passing it, like the following: "test" (with quotes).

Any suggestions?

View Replies !
Read First 10 Lines From A File
I have an ASCII file with each data record on a separateline. Each field is
delimited with a TAB (ASCII 9) character.

Now i want to read the first 10 lines and show them on my site.

This is what i already have reading the first line:

$fname = "http://www.somedomain.com/file.txt";

$fd = fopen($fname, "r");
if ($fd) {
if (!feof ($fd)) {
$buffer = fgets($fd, 4096);
$field = split(chr(9), trim($buffer));
$field0 = "$field[0]";
$field1 = "$field[1]";
}
fclose($fd);
}

echo ("$field0 - $field1");

How can i do this voor the first 10 lines?

View Replies !
How To Loop Through Lines In A File?
I have an array ($data_array) and I want to compare each line of a text file
($counter_file) to each element of the array (the array and the file are in
sync line-for-line). But the file is very big and I don't want to read the
entire file into an array.

In the interest of efficiency, I thought I'd open the file as read only and
loop through and compare each line to the array - since I have to open the
file later in append mode, I thought something like this would work. But
how do I advance the pointer to the next line in the file as the loop
increments?

$fp = fopen($counter_file, "r");
for (i=0; i < count($data_array); i++)
{
$recent_visit = fgets($fp); //<<== * ?
// * how to go to next line as i increments?
if ($recent_visit < TIME1h)
{
$dup_line = explode("|", $data_array[i])
$dup_ip = trim($dup_line[i]);
if ($visip == $dup_ip) //no dupes within one hour
{
exit;
}
}
else
{
break;
}
}
$fp = fopen($counter_file, "a");
[append stuff to counter_file here]

View Replies !
Edit Lines In Txt File
i am trying to write data that i have stored in a session back
to a member.txt, but i am unable to work out why it wont write. It
displays the data i have stored in the session ok, but it wont do the
next step! I have used a similiar script in another part of my web
page which works, but this one won't. From my understanding it has
something to do with if statement if($data[0] == $user_id), so i might
be trying to compare the previouis data to the current data stored in
the txt file properly....

View Replies !
Printing Only Two Lines From A File
I have a file (file01, i.e) like this:

foo
foo
foo
bar
foo
bar
foo

....

Where foo and bar repeats n times, but only foo and bar. What i want to
print is just:

foo
bar

I have tried this:

$myfile=file("file01");

$current_line = reset($myfile);
$first_line = $current_line;

print("First line is: $first_line");

while ($current_line=next($myfile))
{
if ($current_line != $first_line)
{
print("The other line is: $current_line");
break;
}
}

and it works as stand alone, but in the real application, i get:

Fatal error: Cannot break/continue 1 level in
/var/www/html/web/include/functionShow.inc on line 172

View Replies !
Using File() With Blank Lines
Let me admit right up front this is my first foray into php. I'm trying
to simply use a small data file to populate a page. I'm using the
file() function but I want my "data records" to be seperated by a double

My problem is I can't seem to compare a line to anything. My first
problem was determining the end of a data block, finding the double
newline. But in frustration, I just tried to compare a line to a known
value and I still can't compare strings correctly.

Here's a sample data file:

View Replies !
Creating A Pdf File On The Fly With 15 Lines Of Php
I have run across a php script that has about 15 lines of code. With a little re-work I have been able to send form data direct to a template I have created. The problem is, I also have images selected in the form, but the images don't show up... just the url of the image.

View Replies !
Sort Lines In A Txt File
I've formatted a long txt file with 300 lines, where each line consists of comma separated values with 60 fields for each line.

How could i sort all the lines with the second(counting from zero)element in each line as the "sort argument" Code:

View Replies !
Skip Lines In Txt-file
I have to process large files containing "logical" blocks of strings, each
block varying in number of lines.
....
Block number x
string1
string2
....
string n
Block number y
et cetera.

Blocks are read and processed one by one. My GetNextBlock ($index) function
returns an array with all lines in a block, and returns the line number of
the next block header.

What is the fastest way to skip those first <$index -1> lines the next read
? I cannot guarantee (unfortunately) the file is still open, so the file
pointer must be assumed at start of file again.

I had an intermittent solution in which I first split all the blocks into
separate files, but that caused a lot of other unwanted effects beyond the
scope of this posting.

View Replies !
Foreach And Lines In A File
I'm using the following to loop through every line in a file..

foreach ($lines as $line_num => $line){
//do stuff to each line here
}

..that works great. However I wish to start at line 6 of the file, so do exactly the same but skip the first 6 lines. There arent really any 'markers' that stay the same in each file i can just strip from. Cant seem to work this one out.

View Replies !
How Did He Make 10 Lines Read Only From File
How did he make 10 lines read only from file.

View Replies !
Counting Lines In A Flat File
I know that you can count the number of lines with PHP Code:

View Replies !
How To Read Only Some Lines From A Large File
I want to read only some lines from a large text file, say lines 27 through 45. So far, I used PHP Code:

View Replies !
Writing To Multiple Lines In File.
I was wanting to make a list of text field data enetered everytime someone filled out the form. I tried using fwrite() but everytime someone submits on the form it overides the previous entry.

I also tried fwrite($fh "$entry"); but it did the same thing. How can I do this?

View Replies !
Function Like File() But Will Read Lines X Through Y Only?
file() works great, until you start looking at file that are very large,
say 134MB.

Is there any function that will return an array for each line of a file,
but only for lines given as parameters?

A function like file("/path/to/file",100,230) which would return lines 100
through 230 as an array.

View Replies !
Reading Multi-lines In A File...
I'm trying to read multi-lines
from a flat file where a continuation is signalled by the line ending
ina backslash (ASCII 92)

Note 1: this is a windoze box
Note 2: My php.ini is set up with "auto_detect_line_endings = On"

Input file:

View Replies !
Read Only First 10 Lines Of A File Into An Array?
It's nice to be able to generate an html table from a PHP array. I know how to
do this, but the array in question is built from a file. The file in question
can be very long, and I only want the first 10 lines. So, I'd like to reduce
the overhead it takes to read the file into the array by limiting the number of
lines read in - rather than have the entire file read in and then limiting the
output to the html table.

$visits= file("visdata.txt");
//reverse the array so table is ordered by date decending
$visits = array_reverse ($visits);
//show only the last 10 visitors
$number_of_visits = count($visits);
if ($number_of_visits > 10)
{
$number_of_visits = 10;
}
echo
"<table border=&#390;' cellspacing=&#391;' width=ò“'>";
....
....
....
....

View Replies !
Deleting Lines From Flat File
I am trying to display all the news items in my flat file with 'delete' links (<a href="managedeletenews.php?action=delete&id=$key">Delete[/url]) that call the same page to strip out the line and rewrite the file.

However, when the delete link is clicked nothing happens (except the page's address changing from "managedeletenews.php" to the above.

Am I using the references to the $id or $key variables incorrectly?
Is it something to do with the undefined $action variable?
Or is it something else??
BTW, the embedded styles for the delete link - shown below - don't seem to be throwing up any errors. Code:

View Replies !
Reading Character From Lines From A File
I'm using file() to create an array of the lines from a .txt file.  I guess i have two questions.

1) how to I refer to each line individually after the array is created. 

    ie.  do action A to line 5.

2)  how would I search through that line in order to fine a specific character. 

ex.   1 Product Name: Macromedia Director MX 2004 Bible  so I want to loop through to ':' so I can cut of that part of the line and then display the rest of the line.

View Replies !
Parsing File And Printing Only Certain Lines
What's the best way to go about parsing through a file and only writing lines that come after x and stop when y is reached?

Example:
-- Begin X --
We are constantly
trying to improve
phpfreaks and these forums
-- End Y --

View Replies !
Reading A File, Selecting Certain Lines
I have a .txt file that looks like this:

image1.jpg, 15234
image2.jpg, 8752
logo.gif, 1402
blank.png, 120

But it's long, very long. The number after the image is it's size. What I need to be able to do:

Find all the lines that end in .jpg and output them to my screen (the filenames, not the actual images). I don't want to see the filesize and I don't want any gifs, pngs, bmps, etc.

Basically, I know how to put each line into an array, check to see if it ends in .jpg, and output if it does or not, but I don't know how to do this with multiple lines in a .txt file.

Basically I need to know the syntax for "read the first line" "check for .jpg" "check the next line."

I know how to check to see if it's jpg, just not how to go to the next line.

View Replies !
Flat File Display <i>x</i> Number Of Lines
I have a "site updates" script that I wrote that stores my site updates in a flat file in the form:

21234123|>|blah blah blah
21234123|>|blah blah blah
21234123|>|blah blah blah

where 21234123 is a unix timestamp.

what I want, is to be able to display the last x updates on my main page. I have a "updates.php" page which displays ALL updates... but I want to display just the say... most recent 3 or 5 updates at the bottom of my main page.

This is my function that displays -all- updates.

View Replies !
How To Strip Out Unnecessary Lines From Php Fopen File
I have a file that is stored on a computer on my network which i access using fopen for reading. The localpath to the file is http://www.example.com/output.txt

The contents of this file is updated once in a while and basically I need a php script that will open this file, read it and then remove certain things and then save a copy locally.

The contents of this file looks as follows:

Volume in drive C has no label.
Volume Serial Number is A85F-F7AD


Directory of C: est

10/01/2007 01:36 PM <DIR> .
10/01/2007 01:36 PM <DIR> ..
10/01/2007 01:32 PM <DIR> abc
10/01/2007 01:32 PM <DIR> 123
10/01/2007 01:32 PM <DIR> def
10/01/2007 01:32 PM <DIR> 456
0 File(s) 0 bytes
7 Dir(s) 68,797,751,296 bytes free

i want to get rid of the first 7 lines of the file and the last 3 lines. and then on each line i want to get rid of everything before the <DIR> including the <DIR> aswell.

View Replies !
How To Count Lines In A File That Meet Criteria?
Below are the contents file that has the IP address and time of visit of
visitors to a website.

68.122.69.241|1089822686

68.122.69.241|1089823630

68.122.69.241|1089823638

68.122.69.241|1089828547

The second column is the output of time()

I need a script to count each line in this file where the time stamp is
greater than time() - 3600*24. This will give number of visitors in the
last 24 hours. I also need number of visitors in the last 30 days, and
year. Should I use an array?

View Replies !

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