Forum Moderators: coopster

Message Too Old, No Replies

Extracting portions of URL with regex in php

Possible? Resources? Other?

         

ukgimp

12:27 pm on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you were to have 3 types of options for a url, is it possible to extract parts of the url that could be hurled into a variable for a function use.
So that in the following examples it would be possible to have a $var of

$var =””, or $var = “about”, or $var = “uk”, or $var = “us”

extracted from:

h*ttp://www.test.com/
h*ttp://www.test.com/about.php
h*ttp://www.test.com/uk-word/
h*ttp://www.test.com/us-word/

I have done regex for a rewrite using the htaccess before so I am familiar with it but I have not done tiered regex.

$url = $_SERVER['REQUEST_URI'];

then do regex to extract pertinent bit.

Can this be done and if so is this the right approach. If no and no wjat do you suggest.

Cheers

Nick_W

12:29 pm on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you seen this: parse_url() [dk2.php.net] - Might help...?

Nick

ukgimp

12:40 pm on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



your quick Nick :)

I was thinking more along the lines of

if(h*ttp://www.test.com/([a-zA-Z]).php /$1.php) then
{
($var = "$1");
}
else if (h*ttp://www.test.com/([a-zA-Z])-word.php/(*.) /$1.php) then
{
($var = "$1")
}

etc, like in url rewrite

Am I nuts with respect to this idea?

ukgimp

12:53 pm on Nov 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No I am not nuts
[zend.com...]

eregi();
ereg();