Jump to content

explode() help needed


marcus

Recommended Posts

Explode() takes a string as it's second parameter. In your script, the variable $file is a file handle not a string. From the description of what you want to do, it looks like you file contains works seperated by the "*" character and you want to select one at random.

Try this:
[code]<?php
$fc = file_get_contents('facts.txt'); //read the contents of the file into a string
$fc_array = explode('*',$fc); // create the array
echo $fc_array[array_rand($fc_array)]; // use the function array_rand() to get a random index in the $fc_array array.
?>[/code]

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