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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.