Re: Re: Matching a partial string
| From: | Ashley Sheridan | Date: | Sat, 15 Nov 2014 12:09:20 +0000 |
| Subject: | Re: Re: Matching a partial string | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324043@lists.php.net to get a copy of this message | ||
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