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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:46:24+00:00 2026-05-28T06:46:24+00:00

Given a name $path = ‘articles/001.html’; I can check if such a file exists

  • 0

Given a name

$path = 'articles/001.html';

I can check if such a file exists like so:

if ( file_exists( $path ) ) {
    // include it
} else {
    // redirect to articles index
}

However, I was thinking about modifying the URL of the article by adding the title of the article to it. So, if the user requests this URL:

"http://foo.com/articles/001"

I would like to transform the URL to this:

"http://foo.com/articles/001/the-title-of-the-article-here"

Now, this of course means that I have to store the title of that article (and all other articles) somewhere. The title is located in the <h1> element of the article, but I doubt that reading the article (file) on the server just to retrieve the title is a good idea.

So, I was thinking about putting the title in the file name like so:

"001-the-title-of-the-article-here.html"

Then I could just extract it from the file name and add it to the URL. However, I’m not sure how to check if such a file exists in the articles directory – all I got is the article ID (001 in this case).

So, based on an ID, I would like to check if there exists an HTML page inside the articles directory that starts with that ID, and if yes, I would like to retrieve its file name.

Can this be done? Is this a good approach? Suggestions are welcome.

  • 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-28T06:46:25+00:00Added an answer on May 28, 2026 at 6:46 am

    glob can match files according to a pattern for you:

    $files = glob('articles/001-*.html');
    

    It gives you back an array of all matched files.

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

Sidebar

Related Questions

Given a server name and a physical path, I'd like to be able to
Given URL of an archive (e.g. a zip file) Full name (including path) of
I want to get the file name in a given path is there any
Using C++, I need to detect whether given path (file name) is absolute or
Given a path to a file or directory, how can I determine the mount
I'd basically like to get /path/file+name+with+plusses.mp3 to rewrite to /path/file name with plusses.mp3 In
Lets say I have an Areas Table ( id, parentId, name, path ). Given
I have to search a given file name (let say Keyword) in a directory
How can I get an IP address, given a domain name? For example: www.test.com
How to get the first directory name in a relative path, given that they

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.