Jump to content

Pick random sentence from file.


Roelandje

Recommended Posts

Hello everyone,

 

I need to figure out how i can randomly echo a sentence from a file.

I have this piece of code, wich i didnt write myself, but what should work:

 

$zinnen =@file("../data/language.txt");
        if ($zinnen)
            $zin = htmlentities($zinnen[mt_rand(0, count($zinnen)-1)]);

 

 

Then if i Echo $zin, It should give me one sentence from the file 'language.txt'.

Does any of you have a clue of how i should compose that 'language.txt' file?

I need a small example.

 

Thanks in advance.

Roeland

Link to comment
https://forums.phpfreaks.com/topic/252228-pick-random-sentence-from-file/
Share on other sites

What i mean is

 

I have a PHP code that reads a .txt file. It randomly picks a line and shows that.

 

Now, I wonder if there is a way i can do the same thing, but instead of showing sentences from a .txt file, showing HTML codes.

 

So, i can also randomly pick pictures and not just sentences.

 

Thanks for your reaction, tho

I see,

What I've tried now:

 

I made a .txt file with the markup and the image i want to show on one line, I call it images.txt.

like so

 

<!DOCTYPE html><html><head><title>blabla</title></head><body><a href= the whole image thingy></body></html>

 

But it puts out that code in plain writing. It doesnt understand i want it to be treated as HTML instead of TXT.

 

I also tried to save the file as images.html in stead of images.txt... But still, it puts out the code in plain text.

 

This was what you ment, right? Do you happen to see what i do wrong here?

 

Thank you.

Roeland

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.