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 9087239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:39:43+00:00 2026-06-16T21:39:43+00:00

Probably just something small, but I am using the below code to read the

  • 0

Probably just something small, but I am using the below code to read the files inside of a directory and print them out as of a hyperlink to itself.

It prints out the complete file name, but it creates an incomplete hyperlink using only characters up to the first space. The question is how to create a functional hyperlink for a file with spaces in it?

$dir = '.';
$dh = opendir($dir);
$file_count = 0;
while (false !== ($file = readdir($dh))) {
    $files[] = $file;
    $file_count += 1;
    echo $file;
}
for ($x = 0; $x < $file_count; $x += 1) {
    echo "<a href=$files[$x]>" . "$files[$x]" . "</a><br>";
}
  • 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-06-16T21:39:44+00:00Added an answer on June 16, 2026 at 9:39 pm

    You may wish to add quotes to the HREF attribute inside the anchor tag:

     echo "<a href='$files[$x]'>$files[$x]</a><br>";
    

    The client may think the part of the filename following the space is another attribute. (You may also want to use htmlentities() to escape the filenames inside the href attribute.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having a weird issue here. Its probably just something stupid but I dont
Probably I'm just missing something obvious, but I can't get the image in my
This is probably a pretty basic question, but just something that I wanted to
This is probably something really simple but for some reason I just can't seem
This is probably just something I don't understand about c++, but why does this
Bit of a newb but just having a small problem using jquery cycle all
I´ve been stuck on a minor jquery problem, it´s probably just something minor I´m
This is probably just me being stupid somehow or the other, but I am
I am probably missing something quite small and it's frustrating me as I have
I probably just haven't thought this through, or perhaps I'm simply unaware of an

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.