Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4030220
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:26:38+00:00 2026-05-20T11:26:38+00:00

I have this PHP code which attempts to populate an HTML ul list. I’m

  • 0

I have this PHP code which attempts to populate an HTML ul list.

I’m not sure how to put it together. Here is the PHP:

<?php
    $type = 'c';

    $imagesDir = '/prettyphoto/images/';

    $images = glob($imagesDir . $type . '*[TYPE].{jpg,jpeg,png,gif}', GLOB_BRACE);
?>
<ul>
<?php foreach($images as $image): ?>
   <li><a href="<?php echo str_replace('[TYPE]', 'F', $image); ?>"><img src="<?php echo str_replace('[TYPE]', 'T', $image); ?></a>" alt="" /></li>
<?php endforeach; ?>
</ul>

Here is the HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$type = 'N';

$imagesDir = '/prettyphoto/images/thumbnails';

$images = glob($imagesDir . $type . '*[TYPE].{jpg,jpeg,png,gif}', GLOB_BRACE);
?>

<ul>
<?php foreach($images as $image): ?>
   <li><a href="<?php echo str_replace('[TYPE]', 'F', $image); ?>"><img src="<?php echo str_replace('[TYPE]', 'T', $image); ?>" alt="" /></a></li>
<?php endforeach; ?>
</ul>

</body>
</html>

Edit: This simplified script works for me:

<ul>
<?php
foreach (glob("N*T.jpg") as $image): ?>
<li>
  <a href="<?php echo str_replace("T", "F", $image); ?>">
    <img src="<?php  echo "$image"; ?>">
  </a>
</li>
<?php endforeach; ?>
</ul>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:26:39+00:00Added an answer on May 20, 2026 at 11:26 am

    The code as it stands is a little odd, since the first few lines are PHP but they aren’t wrapped in tags. I would also suggest you revise your question to be more specific about what exactly you want to happen.

    In the mean time, I’ll explain the code for you so you can better understand what is going on.

    $type = 'c';
    

    This line seems to modify a parameter to your path select. As of now it is indicating that you are ONLY selecting files which begin with the letter ‘c’.

    $imagesDir = '/prettyphoto/images/';
    

    This is where you specify your images directory (where the files are sitting on the server).

    $images = glob($imagesDir . $type . '*[TYPE].{jpg,jpeg,png,gif}', GLOB_BRACE);
    

    The basic idea of this line is that it collects a list of files which fit a particular form. You can learn more about what this function does by looking at the PHP manual for it

    <ul>
    <?php foreach($images as $image): ?>
       <li><a href="<?php echo str_replace('[TYPE]', 'F', $image); ?>"><img src="<?php echo str_replace('[TYPE]', 'T', $image); ?></a>" alt="" /></li>
    <?php endforeach; ?>
    </ul>
    

    This code is pretty direct — it just iterates through the image and displays each image. the foreach method takes a list and runs the code once for each item in the list. The inner stuff is just constructing an HTML image tag, using the information for the current item.


    Since PHP is a scripting language, you can either keep this block of code together, or separate it to put the variable definitions on the top of the page, and the HTML portion in the HTML. You just have to maintain the same order.

    The key is that the <ul></ul> stuff is output, and you should place it wherever you want it to appear on your page. The $images code can appear at any point, so long as it appears ABOVE the <ul> code.


    It looks like your problem is that [TYPE] is not doing what you expect it to do. Right now it is defining a character class, so it selects files with the letter ‘T’ ‘Y’ ‘P’ or ‘E’ in them.

    Try removing the [TYPE] clause from the glob string by changing it to:
    $images = glob($imagesDir . $type . ‘*.{jpg,jpeg,png,gif}’, GLOB_BRACE);

    Then try print_r($images) to see a list of the images just to help you debug.


    Make sure you read up on how glob works! It will save you time in debugging.

    If you want to find images in a specific path, simply add that path to your glob string.

    In other words, if you wanted all images in ‘/prettyphoto/images/’ you would change

    glob("N*T.jpg")
    

    to

    glob("/prettyphoto/images/N*T.jpg")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this php code, with which I am trying to generate a popup
Let's say I have some code like this: <html> <head><title>Title</title></head> <body> <?php if (!$someCondition){
I have this code in my HTML form: <form action=cart.php method=post> <input type=hidden value=1
I have this PHP code echo '<a href=# onclick=updateByQuery(\'Layer3\', ' . json_encode($query) . ');>Link
Say i have this PHP code: $FooBar = a string; i then need a
I have this code <?php session_start(); if (isset($_GET[cmd])) $cmd = $_GET[cmd]; else die(You should
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I have this rewrite rule RewriteEngine On RewriteBase /location/ RewriteRule ^(.+)/?$ index.php?franchise=$1 Which is
I have some PHP 5.3 code which builds an array to be passed to
I have this login code, which works last night before I slept. Nobody used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.