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
https://forums.phpfreaks.com/topic/25520-explode-help-needed/#findComment-117008
Share on other sites

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.