Re: Re: Matching a partial string
| From: | Peter West | Date: | Sat, 15 Nov 2014 12:54:47 +0000 |
| Subject: | Re: Re: Matching a partial string | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324044@lists.php.net to get a copy of this message | ||
So, the trailing part of the string would be in $matches[2]?
Peter West
"Where the body is, there the eagles will be gathered together."
On 15 Nov 2014, at 10:09 pm, Ashley Sheridan <ash@ashleysheridan.co.uk> wrote:
>
>
> On 15 November 2014 04:32:51 GMT+00:00, Jim Giner <jim.giner@albanyhandball.com> wrote:
>> On 11/14/2014 10:34 PM, Ron Piggott wrote:
>>>
>>> Is there a way (similar to in_array) to match a partial string?
>>>
>>> Haystack:
>>> $_SERVER['REQUEST_URI']
>>>
>>> Needles:
>>> /prayers-for-today/%
>>> /one-year-Bible-reading-guide/%
>>> /past-issues/%
>>>
>>> where % matches the dynamic remainder of the string
>>>
>>> Thank you.
>> Look up the stripos function
>
> I would probably do something like this:
>
> $pattern = '/\/(prayers-for-today|one-year-Bible-reading-guide|past-issues)\/(.+)/';
>
> preg_match($pattern, $_SERVER['REQUEST_URI'], $matches);
>
> $matches will have all your last part in as the second index.
>
> Thanks,
> Ash
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>