Discount Perfume - Gavin Newsom - Debt Consolidation - Myspace Layouts - Apply for Credit Card

PDA

View Full Version : splitting an url


wizzard
Dec 7th 2006, 1:31 am
Hello,

I'm working via modrewrite to pass this:

http://www.test.com/profile/123_text.html
http://www.test.com/profile/text.html

It goes toe prfile.php?id=123_text or prfile.php?id=text

Now in my prfile script i want something that grabs out the 123 out of the id till the _ char.

When there is no 123_ or 454_, ... then it must let the id like it is.

Can someone helps me in here ?

Ow and i'm sorry for my very bad english :(


Cheers
Kris

krakjoe
Dec 7th 2006, 1:47 am
<?
$url = "http://www.test.com/profile/123_text.html";
preg_match("/[0-9]+_/", $url, $matches);
echo "The number you're looking for is stored in . <br>" . '$matches[0]' . " : " . $matches[0];

wizzard
Dec 7th 2006, 2:06 am
Thanks mate :)

krakjoe
Dec 7th 2006, 2:08 am
always a pleasure.....

Juls
Dec 7th 2006, 9:37 pm
I hope that you realize that you need to use that regex in your htaccess file for the mod-rewrite to work properly.

you dont parse the url in the script, you parse it in htaccess and redirect it to the correct page, which then can do additional parsing of the formatted url.

;-)

good luck.

Hello,

I'm working via modrewrite to pass this:

http://www.test.com/profile/123_text.html
http://www.test.com/profile/text.html

It goes toe prfile.php?id=123_text or prfile.php?id=text

Now in my prfile script i want something that grabs out the 123 out of the id till the _ char.

When there is no 123_ or 454_, ... then it must let the id like it is.

Can someone helps me in here ?

Ow and i'm sorry for my very bad english :(


Cheers
Kris