Howto to compare this string :
commodity/search/oil/branch/index
with this :
commodity/search/*/branch/index
It should return true although "oil" is replace with other word.
$match = preg_match("/commodity\/search\/(.*)\/branch\/index/", "commodity/search/someotherword/branch/index");
$match
will be true (or some value evaluating to true, like 1) if a match is found.
Note: the above will match on any extra path, such as commodity/search/some/other/word/branch/index
If you just want to match a single word, but not something resembling a path structure, then you might try something like this:
$match = preg_match("/commodity\/search\/[A-Za-z0-9_-]+\/branch\/index/", "commodity/search/some-OTHER_word/branch/index");
This will only match against upper and lower case a-z characters, numbers, hyphens and underscores. Adjust as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With