Jump to content

[SOLVED] URL Strip


Ken2k7

Recommended Posts

Is there a way to get the URL of a page without actually typing it out and then store that in a variable $url?

 

If so, how can I strip the URL? For example: say the URL is: www.blah.com/ken2k7/page1.php

 

Say I want to get the ken2k7 part and store that into a variable $user, how would I do that? And the URL won't always be that, it can be www.blah.com/newuser/page2.php

 

I just need an efficient way to get the name. Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/65880-solved-url-strip/
Share on other sites

infact thats wrong

 

the reason for the conditional statement is preg_match will return the number of match's while $regs returns the array.. so i format them like this


if (preg_match('%www\.blah\.com/([^/]*)(.*)%i', $data, $regs)) {
$path = $regs[1];
$page = $regs[2];
} else {
$path= "";
$page = "";
}
echo $path;
echo $page;

 

 

Link to comment
https://forums.phpfreaks.com/topic/65880-solved-url-strip/#findComment-329319
Share on other sites

infact thats wrong

 

the reason for the conditional statement is preg_match will return the number of match's while $regs returns the array.. so i format them like this


if (preg_match('%www\.blah\.com/([^/]*)(.*)%i', $data, $regs)) {
$path = $regs[1];
$page = $regs[2];
} else {
$path= "";
$page = "";
}
echo $path;
echo $page;

Ah, I see. Thanks. My last question will be is there a way php can get the URL of the page without me typing '%www.\.blah\.com etc?

Link to comment
https://forums.phpfreaks.com/topic/65880-solved-url-strip/#findComment-329324
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.