Hi. I'm a very new php person. Actually, I'm just a hack and want to thank everyone for this forum. I have strung together a bit of code and I think now I need to create an array to display it, however, for the life of me I just don't get arrays.
What I am doing is trying to format a txt file and display employment opportunities. The numbers of lines will always be changing.
The text file is set up as:
Line 1 = Title
Line 2 = Position
Line 3 = Title
Line 4 = Position
etc
This is my hacked code:
The problem is that the position class has a css border at the bottom and if there are less than 5 positions then I have extra lines, and if there are 6 positions, the sixth one won't display. I'm certain this is easy for someone who knows what they are doing and my lack of array knowledge is really holding me back. Any help would be appreciated?Code:<?php // set source file name and path $source = "scripts/jobs.txt"; // read raw text as array $raw = file($source) or die("Cannot read file"); // retrieve first and second lines (position and description) $title = array_shift($raw); $position = array_shift($raw); $title2 = array_shift($raw); $position2 = array_shift($raw); $title3 = array_shift($raw); $position3 = array_shift($raw); $title4 = array_shift($raw); $position4 = array_shift($raw); $title5 = array_shift($raw); $position5 = array_shift($raw); // 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 $output = // add page content $output .= "<h1 class='title'>$title</h1>"; $output .= "<p class='position'>$position</p>"; $output .= "<h1 class='title'>$title2</h1>"; $output .= "<p class='position'>$position2</p>"; $output .= "<h1 class='title'>$title3</h1>"; $output .= "<p class='position'>$position3</p>"; $output .= "<h1 class='title'>$title4</h1>"; $output .= "<p class='position'>$position4</p>"; $output .= "<h1 class='title'>$title5</h1>"; $output .= "<p class='position'>$position5</p>"; // display in browser echo $output; ?>



Reply With Quote
Bookmarks