Jump to content

a bit rusty with my PHP - need help with fopen


simcoweb

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.

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.