Forum Moderators: coopster

Message Too Old, No Replies

how to get a part of text from url?

         

phprockz

4:39 am on Aug 7, 2006 (gmt 0)

10+ Year Member



Hi everyone,
I wonder how to get a part of url for example lets say i have urls like

1) http://example.com/english/songs.php?cid=some
2) http://example.com/english/lyrics.php?cid=some

I need to take only word "songs" from first url and "lyrics" from second url as variable for another operation.Please tell how it can be done.

thanks.

[edited by: coopster at 11:49 am (utc) on Aug. 7, 2006]
[edit reason]
[1][edit reason] examplified url [/edit]
[/edit][/1]

barns101

10:29 am on Aug 7, 2006 (gmt 0)

10+ Year Member



If the variable will always be called "cid", then you simply use $_GET[cid]

phprockz

1:27 pm on Aug 7, 2006 (gmt 0)

10+ Year Member



Hmm i dont need value of varibale cid.I need songs keyword from songs.php?cid=some.

dreamcatcher

2:18 pm on Aug 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

If you want to check the occurence of something in a string, you can use the strstr [uk.php.net] function.

if (strstr($url, 'songs'))
{
//do something
}

or use the referer:

if (strstr($_SERVER['HTTP_REFERER'], 'songs'))
{
//do something
}

Or are you not sure of the urls and need the value of the page without the .php?

dc

mooger35

5:09 pm on Aug 7, 2006 (gmt 0)

10+ Year Member



if you just want the name of the file without the extension or the directories, this will work

$file_loc = substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'],'.'));
$pagename = str_replace('/','',strrchr($file_loc,'/'));