Page 1 of 1

applying html formatting to different array elements

Posted: Wed Jan 15, 2003 7:05 am
by tobias
I'm doing a class listing for a nonprofit community program

Thus far, I've been able to pull from a text file:

sample of text file:

Code: Select all

Introduction to Databases Using Microsoft Access|CEP #123-B|(10 weeks) 2.4 Continuing Education Units (CEU)|Maurice E. Kennedy, Jr.
The Harlem Renaissance Remembered|CEP #264|Tyrone Stevens Drummond
African-American Reparations: Here & Now|CEP #286 (6 weeks)|Mr. Robert Bell, Mr. Milton McGriff
African American Male/Female Relationships: Surviving the New Millennium|CEP #04-A (8 weeks)|Dara Baye
Hypnotherapy:The Power of the Subconscious Mind|CEP #259|Instructor: J. Joanne Yohannes
The Science of Political Organizing and Organizational Building|CEP #308 (5 weeks)|Instructor: Odinga Mukhtar
Basic Design/Sewing|CEP #213-A (8 weeks)|Instructor: Suzi White
and format it using this piece of code:

Code: Select all

<?
$file = "classes.txt";

$pull = file($file);

	foreach ($pull as $final)
	&#123;
		$final_val = explode("|",$final);

			foreach ($final_val as $output)
				&#123;
					print "<b>$output</b><br />";
				&#125;
			print "<br />";
&#125;
?>
Which give me the an out put like this:

Introduction to Databases Using Microsoft Access
CEP #123-B
(10 weeks) 2.4 Continuing Education Units (CEU)
Maurice E. Kennedy, Jr.

The Harlem Renaissance Remembered
CEP #264
Tyrone Stevens Drummond

...and so on and so forth

I have two questions, first can I get a pointer as how to have the class title bold, the class number italicized? In other words, how to apply different things to elements in my array

and second, is the above code effiecient?

Thank you much

Posted: Wed Jan 15, 2003 7:19 am
by skehoe
Hi,

If every record in the data file contains four fields (seperated by a "|"), you could do something like this after the explode instead of the foreach loop.

Code: Select all

echo "<b>".$final_val&#1111;0]."</b><br>"; // Course Title
echo "<i>".$final_val&#1111;1]."</i><br>"; // Class Number
echo $final_val&#1111;2]."<br>"; // Class Info
echo $final_val&#1111;3]."<br>"; // Instructor
Hope that helps,

~Scott

Posted: Wed Jan 15, 2003 10:53 am
by glo-wurm
may I suggest XML instead of using the text files like that? XML is fairly simple, you will just have to implement an XML parser, or use XML parsing module for PHP. It will be much more scalable, and much more clean to work with :D

otherwise, skehoe's method should work without issue :)

Posted: Thu Jan 23, 2003 11:31 am
by tobias
yes, I'm learning how to apply xml to everyday life now. Thanks for all yall's help.