regex - How do I stop a Regular Expression when I reach a certain character in PHP? -
I have a string, I would like to split into separate array elements using PHP this string, and the following code works fine for this action: 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: It will be: 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: / controller / method / parameter1 / parameter2? Parameter1 = parameter2 . This is just
REQUEST_URI , I am using for my website.
Preeg_split ( '[/]', $ _SERVER ['REQUEST_URI'], NULL, PREG_SPLIT_NO_EMPTY) .
array ([0] => controller [1] => method [2] = & gt; parameter 1 [3] = & Gt; Parameter2? Parameter1 = parameter2)
array ([0] = & gt; Controller [1 ] = & Gt; Method [2] = & gt; Parameter 1 [3] = & gt; Parameter 2)
preg_split ('[/]', Preg_replace ("/ ?? (. *) /", "", $ _SERVER ['REQUEST_URI']), tap, PREG_SPLIT_NO_EMPTY) >
Comments
Post a Comment