Connecting Tech Pros Worldwide Forums | Help | Site Map

duplicates ...arrays + loops

Newbie
 
Join Date: Oct 2006
Posts: 3
#1: Oct 20 '06
this is the code:

[php]
<html>
<head>
<style>
.course_title{font-size: 18px; font-weight: bold}
.professor { font-style: italic; }
.dates { font-weight:bold; }
.location { font-weight:bold; }
.units { font-weight:bold; }
.section { font-style:italics; padding:15px; }
.description { text-indent:20px; font-size:13px; border-top: 1px solid #efefef; padding:10px; }
.ccn { font-size:12px; font-weight:bold; text-align:right; padding:8px; }
.course_wrapper { border: 1px solid #cccccc; padding:10px; font-family:Arial; font-size:13px; margin-bottom:40px; }

</style>

</head>
<body>

<?php
// set source file name and path


$courses = array('courses_19.txt','courses_100b.txt','courses _103.txt','courses_116.txt','courses_121.txt','cou rses_141.txt','courses_147.txt','courses_160.txt', 'courses_163.txt','courses_168.txt','courses_176.t xt','courses_178.txt','courses_179.txt','courses_1 90_1.txt','courses_190_2.txt','courses_190_3.txt', 'courses_199.txt');
$numberofcourses = count($courses);




foreach ($courses as $i) {


$unique_array = array_keys(array_flip($courses));


$raw = file($i) or die("Cannot read file") ;


if ($i == $numberofcourses) {
break; /* You could also write 'break 1;' here. */
}

else {

// retrieve first and second lines (title and author)
$course_title = array_shift($raw);
$professor = array_shift($raw);
$dates = array_shift($raw);
$location = array_shift($raw);
$units = array_shift($raw);
$sections = array_shift($raw);
$description = array_shift($raw);
$ccn = array_shift($raw);


// join remaining data into string


// replace special characters with HTML entities
// replace line breaks with <br />
$html = nl2br(htmlspecialchars($data));

// replace multiple spaces with single spaces
$html = preg_replace('/\s\s+/', ' ', $html);

// replace URLs with <a href...> elements
$html = preg_replace('/\s(\w+:\/\/)(\S+)/', ' <a href="\\1\\2" target="_blank">\\1\\2</a>', $html);

// start building output page
// add page header


// add page content
$output .= "<div class='course_wrapper'>";
$output .= "<div class='course_title'>Legal Studies $course_title</div>";
$output .= "<div class='professor'>Professor $professor</div><p />";
$output .= "<div class='dates'>Dates: $dates</div>";
$output .= "<div class='location'>Room: $location</div>";
$output .= "<div class='units'>$units</div>";
$output .= "<div class='section'>$sections</div>";
$output .= "<div class='description'>$description</div>";
$output .= "<div class='ccn'>CCN:$ccn</div>";
$output .= "<div>$html</div>";
$output .= "</div>";

// add page footer


// display in browser

echo $output;


// AND/OR

// write output to a new .html file


}

}


?>

</body>
</html>
[/php]

and this is basically the order of the content of the txt files that is put out:


19,19

100b 19 100b

103 19 100b 103

116 19 100b 103 116

121, 19, 100b, 103, 116, 121

140 19 100b 103 116 121 140

147 19 100b 103 116 121 140 147

160 19 100b 103 116 121 140 147 160

163 19 100b 103 116 121 140 147 160 163

so im not exactly sure whats going on, can anyone clarify?

its suppose to put out 19, 100b, 103, 116, 121, 140, 147........


much appreciative,

mei

Newbie
 
Join Date: Oct 2006
Posts: 3
#2: Oct 20 '06

re: duplicates ...arrays + loops


i would totally repost this, but

the edit button is missing from this posting

and, my other post was deleted. .....
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#3: Oct 21 '06

re: duplicates ...arrays + loops


The meaning of the following statements escape me, so please explain why you are comparing an array entry name $(i) with a counter ($numberofcourses) and why you want to break if true and build an output string when false.
[php] if ($i == $numberofcourses) {
break; /* You could also write 'break 1;' here. */
}

else {
[/php]
Also what is $data doing here, I cannot see it filled anywhere or do I miss something?
Also $unique_array has no function in what you shoed us.

Ronald :cool:
Reply