Jump to content

Recommended Posts

I've been so busy designing that i've neglected my PHP skills (if I ever had any :) ) I'm hacking around in a random quote display script I downloaded whereas i'm trying to make it work for testimonials. It uses a flat txt file for storing the records. So, i'm trying to write a simple function to display all the testimonials in a formatted table setting. Here's my function:

 

<?php
function showAll() {
$filename = "quotes/testimonials.txt";
$fh = fopen($filename, 'r') or die("Can't open file");
$quotes = fread($fh, filesize($filename));
echo "<table width='90%' align='center' border='0' cellpadding='1' cellspacing='2'>";
	foreach($quotes as $value) {
	echo "<tr><td>$value</td></tr>";
}
echo "</table>";
fclose($fh);
}
?>

 

I get this error message when trying to execute but the argument seems to make sense but is being reported as invalid:

 

Warning: Invalid argument supplied for foreach() in /home2/xxxxxx/public_html/showall.php on line 13

 

I'm sure it's simply my rusty code. I need to write some PHP scripts to keep in practice! Thanks in advance for your help.

Basically i'm trying to open the file, take each line and display it in its own table cell. I'm more used to working with MySQL databases and queries. Either I convert this script to MySQL or figure how to extract each line, separate them and display in a cell. I'll try your suggestion.

Ok, changing the line to file($filename); did the trick as it now reads all the data. Now, another question on this. The info is in a pipe delimited format:

 

some data here | their name | a link here

 

Is there a way to separate these and not display the pipe? Right now it's just treating it all like txt, obviously, so it displays everything.

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.