regex - How do I stop a Regular Expression when I reach a certain character in PHP? -


I have a string, / controller / method / parameter1 / parameter2? Parameter1 = parameter2 . This is just REQUEST_URI , I am using for my website.

I would like to split into separate array elements using PHP this string, and the following code works fine for this action: Preeg_split ( '[/]', $ _SERVER ['REQUEST_URI'], NULL, PREG_SPLIT_NO_EMPTY) .

This works almost completely, provides me excellent ARA output, as long as I do not add the variable Get these variables in the last array element, along with these.

My question is, is there a way to stop processing as well as reaching a question mark (?)?

I want to cut it with a question mark, and show items only before the question mark. This (expected) would mean that:

  array ([0] => controller [1] => method [2] = & gt; parameter 1 [3] = & Gt; Parameter2? Parameter1 = parameter2)   

It will be:

  array ([0] = & gt; Controller [1 ] = & Gt; Method [2] = & gt; Parameter 1 [3] = & gt; Parameter 2)   

The problem is, I want all these in regular expressions. I really do not care if there is another way (I know that there is), I just want to know if it's a way of doing it in regex.

Thanks

You can replace (? *) Using:

  preg_split ('[/]', Preg_replace ("/ ?? (. *) /", "", $ _SERVER ['REQUEST_URI']), tap, PREG_SPLIT_NO_EMPTY) >   

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -