# Solved: How to split url in a string into 2 variables?



## DrP (Jul 23, 2005)

Hello again!

Say I have a string like this:

http://www.juicyreviews.co.uk/nonfiction/

I want to split it into two strings like this:

"http://www.juicyreviews.co.uk/" + "nonfiction/"

I'm sure there will be a function that will let me search for the third "/" and split the string there, but I can't find it anywhere.

Thanks for the help,


----------



## MMJ (Oct 15, 2006)

JavaScript or PHP?

You don't have to split it for PHP you can use *$_SERVER['REQUEST_URI']*, javascript you can use *location.pathname*


----------



## balait243 (Oct 13, 2007)

http://in2.php.net/manual/en/function.explode.php
http://ourtechzone.com


----------



## tomdkat (May 6, 2006)

DrP said:


> I'm sure there will be a function that will let me search for the third "/" and split the string there, but I can't find it anywhere.


indexOf() is the mehod you want. 

Peace...


----------



## DrP (Jul 23, 2005)

Brilliant!

MMJ helped me even though he didn't quite answer my question! My original need was to split the url, but I managed to find a way to do what I wanted using:
$_SERVER['REQUEST_URI']

Thanks for the help,


----------



## MMJ (Oct 15, 2006)

DrP said:


> Brilliant!
> 
> MMJ helped me even though he didn't quite answer my question! My original need was to split the url, but I managed to find a way to do what I wanted using:
> $_SERVER['REQUEST_URI']
> ...


No problem.


----------

