473,670 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read a file with filter, and give the output

Hi!
I would like to create a php script that read a txt file and filter it
with 2 keywords, first keyword deifne the start and the second one the
end of the txt to read.
And then give the output extracted.

Expter of the group, could you help me?
thanks!

Aug 27 '07 #1
2 1225
On Aug 27, 8:31 am, innamorato.pa.. .@gmail.com wrote:
Hi!
I would like to create a php script that read a txt file and filter it
with 2 keywords, first keyword deifne the start and the second one the
end of the txt to read.
And then give the output extracted.

Expter of the group, could you help me?
thanks!
You might be looking for something like the following. I haven't
tested this, so I'm sure my string parsing is off by one, or
something. Also the variable names are kind of long for clarity's
sake; you may want to shorten them.

$file_path = "/path/to/file.txt";
$contents = file_get_conten ts($file_path);

$start_string_p osition = strpos($content s, "start");
$end_string_pos ition = strpos($content s, "end",
$start_string_p osition);
$extracted_stri ng_length = $end_string_pos ition -
$start_string_p osition;

$extracted_stri ng = substr($content s, $start_string_p osition,
$extracted_stri ng_length);

Aug 27 '07 #2
On 27.08.2007 15:31 in************* *@gmail.com wrote:
Hi!
I would like to create a php script that read a txt file and filter it
with 2 keywords, first keyword deifne the start and the second one the
end of the txt to read.
And then give the output extracted.

Expter of the group, could you help me?
thanks!

preg_match('~st art(.*?)end~s',
file_get_conten ts('filename'),
$matches
);

the output will be in $matches[1]

--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi
Aug 27 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
8781
by: Chuck Anderson | last post by:
Can anyone point me in the right direction? I want to use Php to automate confirmation of someone joining an email list by them replying to an email (so they don't have to have a browser?). I will probably use a hyperlink with a unique ID, but I also want to know how to go about reading from a mailbox with Php so I can use an email reply method, too. I'm having trouble finding any kind of tutorial. From the bit of searching I've done,...
1
1484
by: mhenry1384 | last post by:
I am trying to run a program and filter the output on Windows XP. Since I want to filter the output, I'd like to read it a line at a time and only print the lines I care about. p = subprocess.Popen(, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while 1: line = p.stdout.readline() if not line: break
3
2748
by: Bill Cohagan | last post by:
I'm writing a console app in c# and am encountering a strange problem. I'm trying to use redirection of the standard input stream to read input from a (xml) file. The following code snippet is from this app: =============================== static void Main(string args) { if (args.Length > 0) Console.SetIn(new StreamReader(args)); //executes if I don't use the "<", ">" redirection syntax when invoking XmlTextReader xmlin = new...
1
2234
by: Brian Norman | last post by:
Hello Can anyone suggest a way to read the response (I want to write it to a file) in an HttpModule but without using a response filter? I can't see any other way to get at the response stream. Thanks Brian Norman
5
12295
by: Neil Rossi | last post by:
I have an issue with a particular ASP page on two web servers. Let's call these servers Dev1 and Beta1. Both Servers are running IIS 5, Windows 2000 SP4 with "almost" all of the latest patches. On Beta1, I am able to execute a particular page with no problem, that page opens up in the comes up just fine. On Win2kdev1, when I go to execute the same page, it opens a file download dialog and asks me whether I want to open or save the...
4
2290
by: tasahmed | last post by:
Hello Friends, I wrote a function which scans the current working directory and lists out details such as directory/file owner, permission etc. The output of this script can be viewing in the monitor when I give the command print_r which is printed out in a array format. The problem I facing is I want this output in a text file, but I have tried so many things it is not working I am copying my code below, I need help in this urgently....
7
3589
by: theballz | last post by:
Hi, I am learning c programming and come across a problem i cant seem to solve. I have a file which i wish to parse and put certain lines (which do not contain a hash character) into an array and then output the contents of this array. The file seems to be parsed properly and the array gets populated but when I output the array the last line of my text file has filled the array. Text file and code as follows, Text File
0
1504
by: Gabriel Genellina | last post by:
En Tue, 13 May 2008 11:57:03 -0300, Dmitry Teslenko <dteslenko@gmail.com> escribió: Is the code above contained in a function? So all references are released upon function exit? If not, you could try using: del input, output, filter That should release all remaining references to the output file, I presume. Or locate the inner reference to the output file (filter.something perhaps?) and explicitely close it.
2
1396
by: Elliot | last post by:
I am writing a Windows Live Messenger add-in that reads the content of a XML file. However, it does not work(cannot read it) for some computers(I have not summed up the rule). Do you know what can cause this issue? It works on both XP & Vista and Messenger version 8.1 & 8.5, so I do not think it is the matter of OS & Messenger. Any idea would be appreciated.
0
8468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8901
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8660
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.