duplicates ...arrays + loops

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • meithan
    New Member
    • Oct 2006
    • 3

    #1

    duplicates ...arrays + loops

    this is the code:

    [php]
    <html>
    <head>
    <style>
    .course_title{f ont-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','course s_100b.txt','co urses_103.txt', 'courses_116.tx t','courses_121 .txt','courses_ 141.txt','cours es_147.txt','co urses_160.txt', 'courses_163.tx t','courses_168 .txt','courses_ 176.txt','cours es_178.txt','co urses_179.txt', 'courses_190_1. txt','courses_1 90_2.txt','cour ses_190_3.txt', 'courses_199.tx t');
    $numberofcourse s = count($courses) ;




    foreach ($courses as $i) {


    $unique_array = array_keys(arra y_flip($courses ));


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


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

    else {

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


    // join remaining data into string


    // replace special characters with HTML entities
    // replace line breaks with <br />
    $html = nl2br(htmlspeci alchars($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_w rapper'>";
    $output .= "<div class='course_t itle'>Legal Studies $course_title</div>";
    $output .= "<div class='professo r'>Professor $professor</div><p />";
    $output .= "<div class='dates'>D ates: $dates</div>";
    $output .= "<div class='location '>Room: $location</div>";
    $output .= "<div class='units'>$ units</div>";
    $output .= "<div class='section' >$sections</div>";
    $output .= "<div class='descript ion'>$descripti on</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
  • meithan
    New Member
    • Oct 2006
    • 3

    #2
    i would totally repost this, but

    the edit button is missing from this posting

    and, my other post was deleted. .....

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      The meaning of the following statements escape me, so please explain why you are comparing an array entry name $(i) with a counter ($numberofcours es) and why you want to break if true and build an output string when false.
      [php] if ($i == $numberofcourse s) {
      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:

      Comment

      Working...