Showing a weekly program – PHP

  php

Q(Question):

Maybe I haven’t been able to find the answer in Google because I didn’t know
how it is called exactly but I am still puzzling about an easy solution to
update weekly the services of the local church. It should be done without
mySql. The ideal situation would be that php could read the appropiate data
from a text file, so the text file can be easily edited and uploaded by one
of the church’s voluntary workers.
The text file could look like

Zaterdag 25 oktober.
10:00 Pastor P. Jansen
11:00 Pastor W. Dirksen
Zondag 26 oktober.
12:00 Pastor P. Dirks
Zaterdag 1 november
10:00 Pastor J.Hendriks
Zondag 2 november
9:00 Pastor G. de Vries

I would like a function that reads the whole tekst and only publishes the
services for the next weekend. I think I will be able to make a function
that converts the date written in Dutch to an English string and than this
will be converted to a real date, but how can I make php show not only the
date but also the services for that weekend?

If there is info on the web about this, please tell me what keywords I
should enter in Google.

Thanks for any reaction
Martien van Wanrooij

A(Answer):

I noticed that Message-ID: <sUBmb.2426$2o2.18092@amstwist00> from
Martien van Wanrooij contained the following:

Maybe I haven’t been able to find the answer in Google because I didn’t know
how it is called exactly but I am still puzzling about an easy solution to
update weekly the services of the local church. It should be done without
mySql. The ideal situation would be that php could read the appropiate data
from a text file, so the text file can be easily edited and uploaded by one
of the church’s voluntary workers.

It’s a shame if you don’t have access to MySQL. I have written an event
management system that does use MySql and will send you a link to the
test pages for you to try it by email. Updating the events is done via
a web interface. On the web page, the events automatically update
themselves. Events which are in the past are simply not shown.
http://www.antiqueforumgroup.com/pages/brumam.php


Geoff Berrow
It’s only Usenet, no one dies.
My opinions, not the committee’s, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

A(Answer):

"Martien van Wanrooij" <in**@martienvanwanrooij.nl> wrote in message news:<sUBmb.2426$2o2.18092@amstwist00>…

Maybe I haven’t been able to find the answer in Google because I didn’t know
how it is called exactly but I am still puzzling about an easy solution to
update weekly the services of the local church. It should be done without
mySql. The ideal situation would be that php could read the appropiate data
from a text file, so the text file can be easily edited and uploaded by one
of the church’s voluntary workers.
The text file could look like

Zaterdag 25 oktober.
10:00 Pastor P. Jansen
11:00 Pastor W. Dirksen
Zondag 26 oktober.
12:00 Pastor P. Dirks
Zaterdag 1 november
10:00 Pastor J.Hendriks
Zondag 2 november
9:00 Pastor G. de Vries

I would like a function that reads the whole tekst and only publishes the
services for the next weekend. I think I will be able to make a function
that converts the date written in Dutch to an English string and than this
will be converted to a real date, but how can I make php show not only the
date but also the services for that weekend?

If there is info on the web about this, please tell me what keywords I
should enter in Google.

Thanks for any reaction
Martien van Wanrooij

Maybe you could use the function

switch

case

A(Answer):

"Martien van Wanrooij" <in**@martienvanwanrooij.nl> wrote
in message news:<sUBmb.2426$2o2.18092@amstwist00>…

The ideal situation would be that php could read the appropiate data
from a text file, so the text file can be easily edited and uploaded
by one of the church’s voluntary workers.
The text file could look like

Zaterdag 25 oktober.
10:00 Pastor P. Jansen
11:00 Pastor W. Dirksen
Zondag 26 oktober.
12:00 Pastor P. Dirks
Zaterdag 1 november
10:00 Pastor J.Hendriks
Zondag 2 november
9:00 Pastor G. de Vries

I would like a function that reads the whole tekst and only publishes
the services for the next weekend.

Let me try to help, but you’ll have to excuse me for my truly
atrocious Dutch… 🙂

Let’s say you made a slight modification to your file format:

Dadel: Zaterdag 25 oktober.
10:00 Pastor P. Jansen
11:00 Pastor W. Dirksen
Dadel: Zondag 26 oktober.
12:00 Pastor P. Dirks
Dadel: Zaterdag 1 november
10:00 Pastor J.Hendriks
Dadel: Zondag 2 november
9:00 Pastor G. de Vries

Then you could do something like this:

function parseServiceSchedule() {
$monthsE = array (‘January’, ‘February’, ‘March’,
‘April’, ‘May’, ‘June’,
‘July’, ‘August’, ‘September’,
‘October’, ‘November’, ‘December’);
$monthsD = array (‘januari’, ‘februari’, ‘maart’,
‘april’, ‘mei’, ‘juni’,
‘juli’, ‘augustus’, ‘september’,
‘oktober’, ‘november’, ‘december’);
$daysE = array (‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’,
‘Thursday’, ‘Friday’, ‘Saturday’);
$daysD = array (‘zondag’, ‘maandag’, ‘dinsdag’, ‘woensdag’,
‘donderdag’, ‘vrijdag’, ‘zaterdag’);
$schedule = file (‘rooster.txt’);
$output = false;
foreach ($schedule as $line) {
if ($dateD = strstr ($line, ‘Dadel:’)) {
$output = false;
$dateE = str_replace ($monthsD, $monthsE, $dateD);
$dateE = str_replace ($daysD, $daysE, $dateE);
$timestamp = strtotime ($dateE);
$target = strtotime (‘next Saturday 12:00 AM’);
if (($timestamp > $target) and
(($timestamp – $target) < (48*60*60))) {
$output = true;
}
}
if ($output) {
echo $line;
}
}
}

Cheers,
NC

A(Answer):

….Just sent a reply and realized there were a couple of bugs
in it… Here’s the updated (and tested) version:

function parseServiceSchedule() {
$monthsE = array (‘January’, ‘February’, ‘March’,
‘April’, ‘May’, ‘June’,
‘July’, ‘August’, ‘September’,
‘October’, ‘November’, ‘December’);
$monthsD = array (‘januari’, ‘februari’, ‘maart’,
‘april’, ‘mei’, ‘juni’,
‘juli’, ‘augustus’, ‘september’,
‘oktober’, ‘november’, ‘december’);
$daysE = array (‘Sunday’, ‘Monday’, ‘Tuesday’, ‘Wednesday’,
‘Thursday’, ‘Friday’, ‘Saturday’);
$daysD = array (‘Zondag’, ‘Maandag’, ‘Dinsdag’, ‘Woensdag’,
‘Donderdag’, ‘Vrijdag’, ‘Zaterdag’);
$schedule = file (‘rooster.txt’);
$output = false;
foreach ($schedule as $line) {
if ($dateD = strstr ($line, ‘Dadel:’)) {
$output = false;
$dateE = str_replace (‘Dadel:’, ”, $dateD);
$dateE = str_replace ($monthsD, $monthsE, $dateE);
$dateE = str_replace ($daysD, $daysE, $dateE);
$timestamp = strtotime ($dateE);
$target = strtotime (‘next Saturday 12:00 AM’);
if (($timestamp >= $target) and
(($timestamp – $target) < (48*60*60))) {
$output = true;
}
}
if ($output) {
echo $line;
}
}
}

Cheers,
NC

A(Answer):

"Nikolai Chuvakhin" <nc@iname.com> schreef in bericht
news:32*************************@posting.google.co m…

…Just sent a reply and realized there were a couple of bugs
Thank you Nikita, this is really very helpfull. My major problem was the
fact that the date has to be evaluated on these lines were there *is" really
a date in it and I was puzzling how to avoid evaluation of lines without the
date. $schedule = file (‘rooster.txt’);
I didn’t know that accessing a file is that easy. Most documentation talks
about fopen() and similar functions. $dateE = str_replace ($monthsD, $monthsE, $dateE);
$dateE = str_replace ($daysD, $daysE, $dateE);

Another facility that was new for me: the replacing can obviously done by
searching two arrays.
Thanks again,
Martien van Wanrooij

A(Answer):

"Martien van Wanrooij" <in**@martienvanwanrooij.nl> schreef in bericht
news:s7Pmb.2487$2o2.18108@amstwist00…

Thank you Nikita, this is really very helpfull.

Oops, I mean Nikolai ! 🙂 Sorry…

LEAVE A COMMENT