Jump to content

Recommended Posts

Hello every one, I'm sure I'm on the right place.

Firs, I'm new to php but want to learn, so I'm getting to it, but for now here is my problem.

 

I'm building a website (HTML & CSS mostly) for a Christian group, they give me the bible on a text file...

so I suppose I have to put some link (when clicked) to open a PopUp with the correct row from the bible...

Inside that text file, data is separated by tabs, here are a few rows from that file to help me better explain myself.

 

---------------------------------------------------------------------------------------------

1 1 1 1 En el principio creó Dios los cielos y la tierra.

2 1 1 2 Y la tierra estaba desordenada y vacía, y las tinieblas estaban sobre la faz del abismo, y el espíritu de Dios se movía sobre la faz de las aguas.

3 1 1 3 Y dijo Dios: Sea la luz; y fue la luz.

4 1 1 4 Y vio Dios que la luz era buena; y apartó Dios a la luz de las tinieblas.

---------------------------------------------------------------------------------------------

 

The first tab is the order verse #

The second tab is the Book name

The third tab is the chapter

The forth tab is the actual verse #

the fifth tab is the actual text of that verse

 

So far this is what I've gotten: :shrug:


$lines = file("biblia/valera1602_1865.txt");
$books = array(1=>"Genesis"); //etc, etc.
$l_count = count($lines);
foreach($lines as $line) {
    $parts = explode("\t", $line);
    $book  = $books[$parts[1]];
    $chap  = $parts[2];
    $verse = $parts[3];
    $text  = $parts[4];

    echo "{$book} {$chap}:{$verse} {$text}\n";
}

 

 

The problem is it outputs the whole bible with genesis as the name of all the books, of course I dont know how to properly create an array of all books and what I need is to retrieve only one book, one chapter and one verse. I know a database is recommended but my Christian friends just feel more closely to the book if they can see it.

 

 

What I need is to output the verse like this:

1. Ignore first tab

2. Convert the second tab into (a string) the books name (from an array I guess)

3. Output the third and forth tabs next to the outputted string from the second tab with a semicolon in the middle of the third and forth echo string ex. (Genesis 1:1 En el principio creó Dios los cielos y la tierra.)

4. Output the actual verse after the echoed tabs string (like in the example above)

 

I'll attach a couple of files that might help explain myself better.

 

This is possibly a ticket to heaven  ;)  so there. Can some one help me with this?

 

Thank You for your help

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/196284-reading-the-bible-from-a-txt-file/
Share on other sites

to be honest you'd be much better off with this in a database and call the appropriate data from that. You shouldn't be moving all this into an array, since it's going to be cpu intensive if you have to assign it all to arrays each time a call is made to the script

here's how I did it, and it worked:

<?php
$books = array("Genesis","Exodus","Leviticus","Numbers","Deuteronomy","Joshua","Judges","Ruth");
$test_data = "1	1	1	1	En el principio creó Dios los cielos y la tierra.
2	2	1	2	Y la tierra estaba desordenada y vacía, y las tinieblas estaban sobre la faz del abismo, y el espíritu de Dios se movía sobre la faz de las aguas.
3	3	1	3	Y dijo Dios: Sea la luz; y fue la luz.
4	4	1	4	Y vio Dios que la luz era buena; y apartó Dios a la luz de las tinieblas.";
$t_array = explode("\n",$test_data);
foreach ($t_array as $val){
$temp = explode("\t",$val);
$order_of_verse = $temp[0];
$book_name = $books[$temp[1]];
$chapter = $temp[2];
$verse = $temp[3];
$text = $temp[4];
echo "<p><strong>$book_name $chapter : $verse</strong></p>$text\n";
}

I think you missed a step, or didn't post it.

I don't really see the problem apart from not having filled in all the book names.

 

I tried this and it worked for me:

<?PHP
$lines = "verNum	libroNum	capitulo	versiculo	contenido
1	1	1	1	aaaaaaaaaaaaaaaa.
2	1	2	2	bbbbbbbbbbbbbbb.
3	2	1	1	cccccccccccccccc.
4	2	1	2	dddddddddddddddd.
5	3	1	1	eeeeeeeeeeeeeeee.
6	3	1	2	ffffffffffffffff.
7	4	1	1	gggggggggggggggg.
";
$books = array(1=>"Genesis", 2=>"Exodus", 3=>"Leviticus", 4=>"Numbers"); //etc, etc.
$lines = explode("\n", $lines);
$l_count = count($lines);
foreach($lines as $line) {
    $parts = explode("\t", $line);
    $book  = $books[$parts[1]];
    $chap  = $parts[2];
    $verse = $parts[3];
    $text  = $parts[4];

    echo "{$book} {$chap}:{$verse} {$text}<br>";
}
?>

 

I would then recommend putting in something like this:

 

foreach($lines as $line) {
    $parts = explode("\t", $line);
    $book  = $books[$parts[1]];
    $chap  = $parts[2];
    $verse = $parts[3];
    $text  = $parts[4];
    if (isset($_GET['book']) && $book == $_GET['book'] &&
isset($_GET['chap']) && $book == $_GET['chap'] &&
isset($_GET['verse']) && $book == $_GET['verse'] &&
) {
echo "{$book} {$chap}:{$verse} {$text}<br>";
    }
}

 

That way you can send GET variables to retrieve only the correct text. Now this is not very efficient if you are going to loop throught the whole bible every time you make a request. Monitor the performance, but I recommend you put all books into seperate files.

 

I know a database is recommended but my Christian friends just feel more closely to the book if they can see it.

 

Point them to the .frm file :)

 

An easier method is:

 

foreach ($t_array as $val){
list($order_of_verse, $book_name, $chapter, $verse, $text) = explode("\t",$val);
echo "<p><strong>$book_name $chapter : $verse</strong></p>$text\n";
}

 

This is possibly a ticket to heaven

 

I doubt I will ever see/go to that place altough I helped numerous of people. Christianity has a well-known history for burning, abusing, murdering and prosecuting without trial anyone related or in favour of Mathematics (to which we owe the Pentagram's dark background) or Technology (computers are tools of Evil apparently). None of this has any offensive meaning I just want to point out that it is anything but a ticket.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.