How to get part of URL path

Say I want to click on a url path www.something/3/4/5/something

Say 3 and 4 are dynamic, and change relative to link.

Can I just use like preg_match or something in the link www.something/…some code…/…some code…/5/something

Thanks!

Would this work??

Its not on my server, but it seems like it should.

[php]$thumbnail = ‘http://cdn1.image.website.webcdn.com/’ . $_SERVER[‘QUERY_STRING’] . ‘/’ . $_SERVER[‘QUERY_STRING’] . ‘/’.$url_id.’/original/8.jpg’;[/php]

NOTE: the URL_ID variable is what I want to manipulate.

Thanks!

Not quite…

$_SERVER[‘QUERY_STRING’] will return everything after the ? if it is present.

if your URL looked like this:
[php]
www.somesite.com?page=somepage
echo $_SERVER[‘QUERY_STRING’];
//output:
page=somepage
[/php]

If your URL looked like this:
[php]
www.somesite.com
echo $_SERVER[‘QUERY_STRING’];
//output

(will output nothing)
[/php]

How are you creating the links?
Where is the data coming from? (IE:database/textfile/hard coded into page?)

Give me a few more details and we’ll fix it up.
Red :wink:

Links are coming located like this:

[php]cdn1.image.website.webcdn.com/201107/29/607422/original/8.jpg[/php]

So, 201107/29 are the two parts of the path I want to through to get to the video ID 607422.

Once I can get to there, 607422 actually has a variable waiting for it.

Which works very well and displays video when I do this:

[php]$thumbnail = ‘http://cdn1.image.website.webcdn.com/201107/29/’ . $url_id . ‘/original/8.jpg’;[/php]

So, basically, I would like to find out how to power through /201107/29/ to get to $url_id

See, /201107/29/ changes with each image, naturally, as they lead to the video ID where I have a variable waiting.

Just need to get to variable through /201107/29/

THANK YOU for your help :smiley:

will the url always be in this format?
cdn1.image.website.webcdn.com/201107/29/607422/original/8.jpg

I know you said /201107/29/ will be different with each link but will the id your after always be the third directory after the main url?

If so:
[php]<?php
$url = ‘cdn1.image.website.webcdn.com/201107/29/607422/original/8.jpg’;
$arr = explode(’/’, $url);

// $arr[3] is the element you’re after
$url_id = $arr[3];
$url = ‘cdn1.image.website.webcdn.com/201107/29/’ . $url_id . ‘/original/8.jpg’;
?>[/php]

Hope that helps,
Red :wink:

Oh, thank you so much… but I don’t think that is the issue, or I am not explaining myself as well as I should. Please let me try again.

Yes, the format will be:

cdn1.image.website.webcdn.com/201107/29/607422/original/8.jpg

Each video has a video id, /067422/

Which I already have a variable and code waiting once it sees this.

So, once I know /201107/29 – there isn’t a problem with getting thumbnail image of video, cause $url_id variable and its associated code works great.

'cdn1.image.website.webcdn.com/201107/29/' . $url_id . '/original/8.jpg'

BUT when I click on embed video, I don’t know what /201107/29/ is going to be.

So I would like to know what is the php code I would use to get through /201107/29 ?

'cdn1.image.website.webcdn.com/?/?/' . $url_id .'/original/8.jpg'

Now can you see my problem?

Thank you, again, for your help.

using the code i posted below, change this line:
[php]$url = ‘cdn1.image.website.webcdn.com/201107/29/’ . $url_id . ‘/original/8.jpg’;[/php]
to this:
[php]$url = ‘cdn1.image.website.webcdn.com/’ . $arr[1] . ‘/’ . $arr[2] . ‘/’ . $url_id . ‘/original/8.jpg’;[/php]

Let me know how you get on.
Red :wink:

Dang. Nothing happened with thumbnails from video embed link.

So video posts just fine, but still can’t get thumbnails :frowning:

There are no errors, just thumbnails don’t get captured… though they would ONLY if I put the direct link in, which isn’t what I need, as each video embed has it own thumbnail link that shows a picture for that video…and having the same thumbnail link image for every embed would be seriously boring, if not, annoying, and confusing, since each video is different :frowning:

Here is my code, mixed with your suggestions (I changed $url to $thumbnail).

[php]
function video_embed_website_handle_thumbnail($url) {
$name = _video_embed_website_get_video_name($url);
$id = _video_embed_website_get_video_id($url);
$url_id = _video_embed_website_get_video_url_id($url);
$url_name = _video_embed_website_get_video_url_name($url);
$id_url = _video_embed_website_get_video_id_url($url);

$thumbnail = ‘http://cdn1.image.website.webcdn.com/201107/29/’ . $url_id . ‘/original/8.jpg’;
$arr = explode(’/’, $thumbnail);
$url_id = $arr[3];

$thumbnail = ‘http://cdn1.image.website.webcdn.com/’ . $arr[1] . ‘/’ . $arr[2] . ‘/’ . $url_id . ‘/original/8.jpg’;
return array(
‘name’ => $name,
‘id’ => $id,
‘url_id’ => $url_id,
‘url_name’ => $url_name,
‘id_url’ => $id_url,
‘url’ => $thumbnail,
);
}

[/php]

PS i would give you the url of the site I am trying to capture images for each video, BUT that isn’t an issue, and phphelp won’t let me.

That function doesn’t make sense?
On the one hand you’re passing in a url, then inside the function you are manipulating a hard coded url which will always return the same value(s).

Replace that function with this one and let me know how you get on.
[php]function video_embed_website_handle_thumbnail($url) {
$name = _video_embed_website_get_video_name($url);
$id = _video_embed_website_get_video_id($url);
$url_id = _video_embed_website_get_video_url_id($url);
$url_name = _video_embed_website_get_video_url_name($url);
$id_url = _video_embed_website_get_video_id_url($url);

$arr = explode('/', $url);
$thumbnail = $arr[0] . '/' . $arr[1] . '/' . $arr[2] . '/' . $arr[3] . '/original/8.jpg';

return array(
	'name' => $name,
	'id' => $id,
	'url_id' => $url_id,
	'url_name' => $url_name,
	'id_url' => $id_url,
	'url' => $thumbnail,
);

} // end function.

// This is the url you supplied, you should replace this with your code to get the actual url.
$url = ‘cdn1.image.website.webcdn.com/201107/29/607422/original/8.jpg’;

// call the function.
$thumb_url = video_embed_website_handle_thumbnail($url);
[/php]

Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service