Jump to content

Error Displaying One Line From A File


TheHaloEffect

Recommended Posts

I'm trying to make a script that randomly pulls one line out of a text file, replaces the wrod fname with the users input, and then outputs it into the web browser.  I've had loads of trouble with it since i'm not exactly pro with php, but i managed to get there in the end, and i've narrowed it down to one final error...It's displaying everything from a text file instead of just the one line. 
The code is attached below, i've tried adding implode and explode, i don't know how that was meant to work, but somebody suggested it on another forum.  Any help please?
Pretty desperate now, been bugging me for absolutely ages :(



[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Fact Generator</title>

</head>



<body>

<div align="center">

  <p>&nbsp;  </p>

  <p>

<?php

if(isset($_POST['fname'])) {

    $fname = $_POST['fname'];

    $filename = "facts.php";

    $filedata = file($filename);

    shuffle($filedata);

    $farray = str_replace(fname, $fname, $filedata[array_rand($filedata)]);

    foreach($filedata as $farray) {

        echo wordwrap($farray,50,"<br/>");    }

}

?>

    </p>

    </div>

  </p>

</div>

<p align="center">&nbsp;</p>

  <p align="center">&nbsp;</p>

  <p align="center">&nbsp;</p>

<p align="center" class="style4">Enter your name: </p>

<p align="center">

<form action="factgen.php" method="post" target="_self" />



  <input type="text" size="30" name="fname" value="<?php echo $fname; ?>"/>

  </p>

<p align="center">

<input type="submit" value="Fact!" /></p>

<p align="center">&nbsp;</p>





</body>

</html>[/code]
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.