By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,747 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,747 IT Pros & Developers. It's quick & easy.

Strip URL into its parts

100+
P: 133
Hi,

I am trying to strip down a url like this:

http://www.website.co.uk/word-word-word/word-word-word.html

I just want to extract the bold section between the / / and remove the - does anyone know how i can do this.

Cheers,
Adam
Feb 14 '08 #1
Share this Question
Share on Google+
4 Replies


ronverdonk
Expert 2.5K+
P: 4,258
I would like to help you, but I always use a javascript routine that returns all elements of an url/uri in an array. If you want that I'll show it. If you insist on PHP code, I'll pass.

Ronald
Feb 14 '08 #2

100+
P: 133
I would like to help you, but I always use a javascript routine that returns all elements of an url/uri in an array. If you want that I'll show it. If you insist on PHP code, I'll pass.

Ronald
PHP Only, sorry.

Cheers for the offer though.
Feb 14 '08 #3

nomad
Expert 100+
P: 664
Hi,

I am trying to strip down a url like this:

http://www.website.co.uk/word-word-word/word-word-word.html

I just want to extract the bold section between the / / and remove the - does anyone know how i can do this.

Cheers,
Adam
Adam:
Please take a look at this tread it might help you.
http://www.thescripts.com/forum/thread770629.html

nomad
Feb 14 '08 #4

ronverdonk
Expert 2.5K+
P: 4,258
That ereg_match will result in
Expand|Select|Wrap|Line Numbers
  1. /word-word-word/word-word-word.html
Now when you can live with that, you can find what you want using PHP, as sample:
[php]
$text='http://www.website.co.uk/word-word-word/word-word-word.html';
preg_match_all("/^(https?:\/\/)?([^\/]*)(.*)/i", "$text", $matches);
echo dirname($matches[3][0]);[/php]
That will give you
Expand|Select|Wrap|Line Numbers
  1. /word-word-word
Ronald
Feb 15 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.