How do you insert a variable to replace url dynamic path?

I need to know how to create a function to insert a variable to read the url path.

http://cdn1.image.website.webcdn.com/555/folder/video_id/original/8.jpg

Basically, I want to know what or how to make a function to I can place a variable in 555, because 555 path is actually dynamic and changes depending on video.

Thank you for your help!

[php]$path = “http://cdn1.image.website.webcdn.com/” . $variable . “/folder/video_id/original/8.jpg”;[/php]

Or something like …

[php]$path = preg_replace("#(http://[^.]+.[^.]+.[^.]+.[^.]+.com/)\d+(/[^/]+/[^/]+/[^/]+/\d.jpg)#","$1$variable$2");[/php]

… if you don’t know the url exactly.

I’ll give it a shot, and update us soon.

Thanks for the suggestions!!!

Okay, more details on my intentions, so I can clarify issue better:

The url that has thumbnail images linked to its videos that are located like this:

http://cdn1.image.webiste.webcdn.com/5/6/7/160x120/8.jpg

7 in the path, is the actual video id with respective video I am interested in.

5 and 6 in the path, are dynamic too, and also change with video I am interested in.

If I use the above link, I can see the video thumbnail in browser.

If I use this code, I can take that video thumbnail, and for that particular video (referencing path 5 and 6), and it comes to my website:

[php]thumbnail = ‘http://cdn1.image.website.webcdn.com/5/7/’.$url_id.’/160x120/8.jpg’;
[/php]

BUT, if I use this code now, with paths 5 or 6 having the variables too, it fails:

[php]]$thumbnail = ‘http://cdn1.image.website.webcdn.com/’.$id_url.’/’.$url_name.’/’.$url_id.’/160x120/8.jpg’;[/php]

My code, what is giving me problems is this:

[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/’.$id_url.’/’.$url_name.’/’.$url_id.’/160x120/8.jpg’;
return array(
‘name’ => $name,
‘id’ => $id,
‘url_id’ => $url_id,
‘url_name’ => $url_name,
‘id_url’ => $id_url,
‘url’ => $thumbnail,
);
}

function _video_embed_website_split($s, $str) {
$ret = array();
$tmp = ‘’;
$size = strlen($str);
for ($i = 0; $i < $size; $i++) {
$char = substr($str, $i, 1);
if ($char == $s) {
$ret[] = $tmp;
$tmp = ‘’;
}
else {
$tmp .= $char;
}
}
if ($tmp) {
$ret[] = $tmp;
}
return $ret;
}

function _video_embed_website_get_video_id_url($url) {
$matches = array();
$matches = _video_embed_website_split("/", $url);
$index = count($matches) - 5;
if ($matches[$index]) {
return $matches[$index];
}
return FALSE;
}

function _video_embed_website_get_video_url_name($url) {
$matches = array();
$matches = _video_embed_website_split("/", $url);
$index = count($matches) - 4;
if ($matches[$index]) {
return $matches[$index];
}
return FALSE;
}

function _video_embed_website_get_video_url_id($url) {
$matches = array();
$matches = _video_embed_website_split("/", $url);
$index = count($matches) - 3;
if ($matches[$index]) {
return $matches[$index];
}
return FALSE;
}

function _video_embed_website_get_video_id($url) {
$matches = array();
$matches = _video_embed_website_split("/", $url);
$index = count($matches) - 2;
if ($matches[$index]) {
return $matches[$index];
}
return FALSE;
}

function _video_embed_website_get_video_name($url) {
$matches = array();
$matches = _video_embed_website_split("/",$url);
if (end($matches)) {
return end($matches);
}
return FALSE;
}
[/php]

Thanks again!

Only correction:

[php]]$thumbnail = ‘http://cdn1.image.website.webcdn.com/’.$id_url.’/’.$url_name.’/’.$url_id.’/160x120/8.jpg’;[/php]

Should be:

[php]$thumbnail = ‘http://cdn1.image.website.webcdn.com/’.$id_url.’/’.$url_name.’/’.$url_id.’/160x120/8.jpg’;[/php]

Forgot to delete the extra ]

And yes, I still need help, the “correction” post was just that… I wish we could just edit our original posting :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service