<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Random text' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Random text' posted on the 'PHP' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 04:42:34 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 04:42:34 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Random text</title>
      <link>http://www.programmersheaven.com/mb/phpstuff/263956/263956/random-text/</link>
      <description>How would you pick a random piece of text from a text file and store it in a variable?&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/phpstuff/263956/263956/random-text/</guid>
      <pubDate>Tue, 22 Jun 2004 01:47:54 -0700</pubDate>
      <category>PHP</category>
    </item>
    <item>
      <title>Re: Random text</title>
      <link>http://www.programmersheaven.com/mb/phpstuff/263956/264030/re-random-text/#264030</link>
      <description>: How would you pick a random piece of text from a text file and store it in a variable?&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
This is how I would do it... roughly.&lt;br /&gt;
Let's say that the file looks like this:&lt;br /&gt;
&lt;span style="color: Red;"&gt;foo&lt;br /&gt;
bar&lt;/span&gt;&lt;br /&gt;
&lt;pre class="sourcecode"&gt;&amp;lt;?php
$fopened = fopen(file, r); //Open the file... just for reading.
$string = fread(fopened); //Read it into a string.
$exploded = explode("/r/n", $string); //Separate it by newline into an array.
$rand = rand(0, count($exploded)); //Randomize a number between 0 and the number of elements of the array.
echo "The random word is:/n". $exploded[$rand]; // Echo element $rand of array $exploded
fclose(file); //Close it.
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
That's how I would do it. It would either echo "foo" or "bar." Now, if you wanted to separate the words by spaces, not new lines, you would just change the "/r/n" to " ".&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/phpstuff/263956/264030/re-random-text/#264030</guid>
      <pubDate>Tue, 22 Jun 2004 08:11:39 -0700</pubDate>
      <category>PHP</category>
    </item>
    <item>
      <title>Re: Random text</title>
      <link>http://www.programmersheaven.com/mb/phpstuff/263956/264039/re-random-text/#264039</link>
      <description>: : How would you pick a random piece of text from a text file and store it in a variable?&lt;br /&gt;
: : &lt;br /&gt;
: : &lt;br /&gt;
: This is how I would do it... roughly.&lt;br /&gt;
: Let's say that the file looks like this:&lt;br /&gt;
: &lt;span style="color: Red;"&gt;foo&lt;br /&gt;
: bar&lt;/span&gt;&lt;br /&gt;
: &lt;pre class="sourcecode"&gt;&amp;lt;?php
: $fopened = fopen(file, r); //Open the file... just for reading.
: $string = fread(fopened); //Read it into a string.
: $exploded = explode("/r/n", $string); //Separate it by newline into an array.
: $rand = rand(0, count($exploded)); //Randomize a number between 0 and the number of elements of the array.
: echo "The random word is:/n". $exploded[$rand]; // Echo element $rand of array $exploded
: fclose(file); //Close it.
: ?&amp;gt;
: &lt;/pre&gt;&lt;br /&gt;
: That's how I would do it. It would either echo "foo" or "bar." Now, if you wanted to separate the words by spaces, not new lines, you would just change the "/r/n" to " ".&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
makes sense to me, only one problem - i dont know how to tell it *what* file to open :P&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/phpstuff/263956/264039/re-random-text/#264039</guid>
      <pubDate>Tue, 22 Jun 2004 09:28:17 -0700</pubDate>
      <category>PHP</category>
    </item>
    <item>
      <title>Re: Random text</title>
      <link>http://www.programmersheaven.com/mb/phpstuff/263956/264068/re-random-text/#264068</link>
      <description>&lt;pre class="sourcecode"&gt;&amp;lt;?php
$fopened = fopen(&lt;span style="color: Blue;"&gt;file&lt;/span&gt;, r); //Open the file... just for reading.
$string = fread($fopened); //Read it into a string.
$exploded = explode("/r/n", $string); //Separate it by newline into an array.
$rand = rand(0, count($exploded)); //Randomize a number between 0 and the number of elements of the array.
echo "The random word is:/n". $exploded[$rand]; // Echo element $rand of array $exploded
fclose(file); //Close it.
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
: makes sense to me, only one problem - i dont know how to tell it *what* file to open :P&lt;br /&gt;
&lt;br /&gt;
Replace the word "file" in blue above with the path of the text file you want to look through.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/phpstuff/263956/264068/re-random-text/#264068</guid>
      <pubDate>Tue, 22 Jun 2004 12:20:23 -0700</pubDate>
      <category>PHP</category>
    </item>
    <item>
      <title>Re: Random text</title>
      <link>http://www.programmersheaven.com/mb/phpstuff/263956/264286/re-random-text/#264286</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by GameFreak7744 at  2004-6-23 22:6:25&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
i'm getting some big bad errors that i cant fix:&lt;br /&gt;
&lt;br /&gt;
Warning: Wrong parameter count for fread() in /home/public2/public_html/indexframe.php on line 25&lt;br /&gt;
""&lt;br /&gt;
Warning: fclose(): supplied argument is not a valid stream resource in /home/public2/public_html/indexframe.php on line 29&lt;br /&gt;
&lt;br /&gt;
any ideas?&lt;br /&gt;
&lt;br /&gt;
EDIT: RE-the second error, um, should it be 'fclose($fopened)' rather than the file path?&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/phpstuff/263956/264286/re-random-text/#264286</guid>
      <pubDate>Wed, 23 Jun 2004 21:58:55 -0700</pubDate>
      <category>PHP</category>
    </item>
    <item>
      <title>Re: Random text</title>
      <link>http://www.programmersheaven.com/mb/phpstuff/263956/264423/re-random-text/#264423</link>
      <description>the parameters of fopen are (string filename,string mode)&lt;br /&gt;
so it's&lt;br /&gt;
&lt;span style="color: Red;"&gt;'file'&lt;/span&gt;,not file&lt;br /&gt;
&lt;span style="color: Red;"&gt;'r'&lt;/span&gt;,not r&lt;br /&gt;
you can also use array_rand function:&lt;pre class="sourcecode"&gt;echo"The random word is:".$exploded[array_rand($exploded)];&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/phpstuff/263956/264423/re-random-text/#264423</guid>
      <pubDate>Thu, 24 Jun 2004 22:52:52 -0700</pubDate>
      <category>PHP</category>
    </item>
    <item>
      <title>Re: Random text</title>
      <link>http://www.programmersheaven.com/mb/phpstuff/263956/264436/re-random-text/#264436</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by GameFreak7744 at  2004-6-25 1:56:42&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: the parameters of fopen are (string filename,string mode)&lt;br /&gt;
: so it's&lt;br /&gt;
: &lt;span style="color: Red;"&gt;'file'&lt;/span&gt;,not file&lt;br /&gt;
: &lt;span style="color: Red;"&gt;'r'&lt;/span&gt;,not r&lt;br /&gt;
: you can also use array_rand function:&lt;pre class="sourcecode"&gt;echo"The random word is:".$exploded[array_rand($exploded)];&lt;/pre&gt;&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
yeah. i can also use 'file_get_contents' rather than 'fopen' and then 'fread'&lt;br /&gt;
&lt;br /&gt;
EDIT:&lt;br /&gt;
I also find it better to use '#' insted of next line or space. however (no matter which kind i use) when it shows the last on in the file it adds a space to the end of it, any ideas how to remove this.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/phpstuff/263956/264436/re-random-text/#264436</guid>
      <pubDate>Fri, 25 Jun 2004 01:50:34 -0700</pubDate>
      <category>PHP</category>
    </item>
  </channel>
</rss>