Yehonatan
Yehonatan

Reputation: 3225

preg_match gives only one match

I'm trying to create a url handler and I tried to use preg_match for finding the variables. So here is the preg_match that I get after the variable replacing of the url format (ex:post/%id%/%title%) -

preg_match("/post\/[0-9]+\/[a-z-א-ת-]+/i","post/5/lol",$match);

My problem that $match returns only this inside array -

"post/5/lol"

And not an array like that -

Array ( 
        [0] => "post/5/lol",
        [1] => "5",
        [2] => "lol"
      )

Can someone help me please to find out why it returns only one match?

Upvotes: 2

Views: 3322

Answers (1)

user142162
user142162

Reputation:

Wrap each segment you wish to capture with parentheses, creating sub-expressions:

preg_match("/post\/([0-9]+)\/([a-z-א-ת-]+)/i", "post/5/lol", $match);

Upvotes: 6

Related Questions