/    Sign up×
Community /Pin to ProfileBookmark

Specific Text selection

Hi guys,

I’m sorry if this is covered in a previous thread, but I couldn’t see it while I skimmed through.

I am brand new to self developed sites (ie: I have never had to code my self before, using only the likes of wordpress and joomla!).

I am desiging a site for a church that requires a daily Bible reading schedule to be put up. I have a .txt file that lists the applicable daily readings, with each day on a separate line, but don’t know how to code PHP to make it happen.

Is there anyone out there who can assist me?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@badbenMar 16.2012 — What exactly do you want to do with the daily readings?

Do you want to display them in a html table, import them to a database, upload the .txt file to your website.

Please provide a little more information so that I may help.

Thanks
Copy linkTweet thisAlerts:
@WyCnetMar 16.2012 — Use an XML file to hold your data, rather than a text file. You have various options from that point on. You can have your page look for an XML file with a date on it, like: "dailyReading20120401.xml", if the readings differ from week to week. If the daily readings are fixed then the xml file could contain a Monday, Friday, Sunday section.

If you wish to send the daily readings with the page you can use php to access the XML file and read the appropriate section in an ordered way.
Copy linkTweet thisAlerts:
@jimoauauthorMar 17.2012 — Hi guys,

Thanks for the replys.

The text will be displayed in a div box. All I need it to do is select the correct line of text to display according to the day of the week. I have a random text selector (in PHP) that will select a line of text from a .txt file to display in a similar fashion, but for this particular item I obviously want it to take it in the correct order, not random.

I am definatley open to advise, so if an xml file is a better option, I will run with that- but the scripting to get the correct line is where I am now stuck. If date is a bad option (I don't need year, just month and day) I can number each line 1-365 if that would work better?

Thanks for your help!
Copy linkTweet thisAlerts:
@WyCnetMar 17.2012 — For month based information the XML file can have the following schema.


<?xml version="1.0" encoding="UTF-8"?>
<index>
<March>
<Monday>
<reading>11:30AM :: John the Baptist</reading>
<reading>19:30PM :: Father Scroll</reading>
</Monday>

<Saturday>
<reading>11:30AM :: John the Baptist</reading>
</Saturday>
</March>

<December>
<Christmas day>
<reading>19:30PM :: The Holy Spirit</reading>
</Christmas day>
</December>

<index>
Copy linkTweet thisAlerts:
@badbenMar 17.2012 — I agree that xml is probably a better way of doing things.

If you use an xml format like in a file called readings.xml:

[CODE]
<?xml version="1.0"?>
<Readings>
<Reading date="2012/03/17" reader="John Smith">John The Baptist</Reading>
<Reading date="2012/03/18" reader="Fred Bloggs">The Holy Spirit</Reading>
</Readings>
[/CODE]


then the following code would show all the readings for today's date:

[code=php]
<?php

$today = date('Y/m/d');

$xmlDoc = new DOMDocument();
$xmlDoc->load( 'readings.xml' );

$readings = $xmlDoc->getElementsByTagName('Reading');
if ($readings) {
foreach ($readings as $reading) {
$date = $reading->getAttribute('date');
if ($date == $today) {
echo $passage = $reading->nodeValue;
echo " to be read by ".$reading->getAttribute('reader')."<br />";
}
}
}
?>
[/code]
Copy linkTweet thisAlerts:
@jimoauauthorMar 17.2012 — Thanks for the scripts.

I have been looking at this, but as I said earlier, I am a total newbie at this.:o

What is the best way for me to include this script in the site. Do I put that script directly into the <div> tag? or reference to it as a < script > tag?

I thank you for the education. I hope to be able to pass on the goodwill when I have learned some!
Copy linkTweet thisAlerts:
@badbenMar 17.2012 — simply place the code in your <div> tag. The <?php and ?> specify the php code.
Copy linkTweet thisAlerts:
@jimoauauthorMar 18.2012 — Again, thank you.

I have tried that, but the code does not seem to be working. I copied and pasted (changing file names and directories) and even tried just typing it in again, but all I get in my div is the actual code.

I typed it in to a new php file, and it worked all good. This is the code for that part of the page:
<div id="apDiv17">

<?PHP

$today = date ( m/d );

$xmlDoc = new DOMDocument ();

$xmlDoc->load ( "Reading/readings1.xml" );

$readings = $xmlDoc->getElementsByTagNameNS( "Reading" );

if ($readings) {

foreach ($readings as $reading) {

$date = $reading->getAttribute ("date");

if ($date == $today) {

echo $passage = $reading->nodevalue;

echo "to be read by".$reading->getAttribute ("reader")."</br>";

}

}

}

?>

</div>

</body>

</html>[/QUOTE]


Does anything in there look wrong?

Thanks
×

Success!

Help @jimoau spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...