473,512 Members | 15,363 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 1219
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_contents($file_path);

$start_string_position = strpos($contents, "start");
$end_string_position = strpos($contents, "end",
$start_string_position);
$extracted_string_length = $end_string_position -
$start_string_position;

$extracted_string = substr($contents, $start_string_position,
$extracted_string_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('~start(.*?)end~s',
file_get_contents('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
8746
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...
1
1481
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 =...
3
2738
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...
1
2232
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...
5
12272
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. ...
4
2278
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...
7
3572
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...
0
1494
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...
2
1390
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...
0
7252
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,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
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...
1
7093
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...
0
7517
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...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5077
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...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.