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
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.