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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:18:26+00:00 2026-06-15T12:18:26+00:00

so I made an routing system in PHP… So I made a route called

  • 0

so I made an routing system in PHP…

So I made a route called /post/:id, but whenever I print_r my $matches I get this:

Array ( [0] => /post/10 [d] => 10 [1] => 10 ) 1

That ‘d’ in the array should obviously be ‘id’, anyone know how to fix this?

Thx

    <?php
    public function setPattern($pattern)
    {
            $this->_pattern = $pattern;
            $this->_regex = preg_replace('#:([a-z])+$#', "(?P<$1>[^/]+)", $pattern);
    }

    public function match($uri)
    {

            if (!preg_match("#" . $this->_regex . "$#", $uri, $matches))
            {
                    return false;
            }
            else
            {
                      return $matches;
            }
    }
  • 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-15T12:18:27+00:00Added an answer on June 15, 2026 at 12:18 pm

    You only capture one character in your preg_replace call. Try this and put the + sign in the capture to get multiple characters:

    $this->_regex = preg_replace('#:([a-z]+)$#', "(?P<$1>[^/]+)", $pattern);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a commenting system and I am trying to get it to post
I am using System.Web.Routing in the Asp.Net Webform Application. I wrote the following route
For RESTful purpose, I made my routing just like this: routes.rb match 'shops/:sort/:genre/:area', :to
Looking for simple php class routing, like this: http://fatfree.sourceforge.net/page/routing-engine Is there a ready-made solutions?
I'm trying to work through this guide to Rails routing , but I got
Made this nice little loop for hiding and showing div's, works as a charm
Made a custom obj called Item with some string fields and one float. .h
I made a dll in c# but i need to export the functions. Is
I made a little PHP script that checks if an email is valid. The
I have a simple ASP.NET 3.5 SP1 Web Forms app... I've added the System.Web.Routing

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.