Look for phrase in string, and also look for wildcards after the phrase

49 views Asked by At

I'm looking for a way to display some code based on the URL of the site.

Case 1:

If url contains getting-started do something

Case 2:

If url contains getting-started/* (could be anything) show something else.

I'm currently getting the URL string as:

$url = $_SERVER['REQUEST_URI'];

And then performing strpos

if (strpos($slug,'getting-started')){

But I need something to specifically target URLs where the end is getting-started and also be able to identify when there is more that comes after it.

1

There are 1 answers

0
Jay Blanchard On

You should use regex:

(getting-started)$ // gets the phrase at the end of the string
(getting-started)(.*) // gets the phrase + anything else 

You could combine this with preg_match()