Click to See Complete Forum and Search --> : [RESOLVED] Limiting Display of Bullets on Page (REGEX?)


abovethefold
07-19-2007, 12:15 PM
I need help with crafting an expression that will allow me to limit the number of bullets shown on a web page (called Page A), while display the full list of bullets on a page deeper in the site (called Page B). Content (i.e. the copy and links) inside each bullet are managed by someone who knows very little HTML, so I have only presented this individual with a file that contains just the bullets (for purposes of this thread, we'll call it bullets.php)

<ul>
<li>Date</a><br/><strong>name of the link</a><br/><a href="filename.wma" target="_blank">Download &amp; Listen (filesize and length)</a><br/>Approx. Download Time: 1 min<br/></li>
<li>...</li>
<li>...</li>
<li>...</li>
</ul>
If I want to right an expression, albeit Regex, how would I be able to limit the number of bullets in bullets.php so that Page A only shows two bullets while Page B shows the entire list...basically an archive page.

The reason I am guessing a regular expression is because I need to keep the HTML "as is" in bullets.php and have an expression outside of this file control the display.

Much help is appreciated.

Sheldon
07-19-2007, 06:29 PM
I wouldn't use regex, i'd use something like;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>Bullets</title>

</head>

<body>

<ul>
<?php

$lines = file('bullets.php');
$limit = "10";
foreach ($lines as $line_num => $line) {
if($line_num <= $limit){
echo(htmlspecialchars($line));
}
}
?>
</ul>

</body>
</html>

abovethefold
07-19-2007, 07:56 PM
Works like a charm and it's very lightweight...good call!