Re: Testing a URL with regex
| From: | Ashley Sheridan | Date: | Wed, 07 Jan 2009 21:49:44 +0000 |
| Subject: | Re: Testing a URL with regex | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-285613@lists.php.net to get a copy of this message | ||
On Wed, 2009-01-07 at 20:24 +0800, Sn!per wrote:
> Let's say I have these URLs
>
> http://example.com/index.php?q=gallery
> http://example.com/index.php?q=gallery&g2_itemId=81
> http://example.com/index.php?q=gallery&g2_itemId=100
>
> I want to have a line of code that will extract just the
> "http://example.com/index.php?q=gallery" part of the
> URL.
>
> I am never good with regex, please help. TIA.
>
> --
> roger
>
>
>
>
> --
> Sign Up for free Email at http://ureg.home.net.my/
>
>
Why do you need a regex here? All the URL's have the same foremost
component, which is exactly 38 characters in length. Do you perchance
need a regualr expression to parse other URL's?
If you just need to extract everything before the first ampersand, then
strpos and substr would be the best to use.
Ash
www.ashleysheridan.co.uk