Jump to content

how: find a line replace it and return just that change line?


SnakZ

Recommended Posts

what im trying to do is take a youtube embed code find the URL code for that video and remove all other parts of the code keeping only the URL of the video

after i get the URL by it self then replace the http://www.youtube.com/ part of the URL with http://i2.ytimg.com/vi/

 

to do this i know that i need something like this to get the URL of the video

http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+)

but how to only return just the URL is something idk how to do

 

then use str_replace http://www.youtube.com/(?:v|cp)/" with  http://i2.ytimg.com/vi/

 

so in the end im asking if anyone know how to remove all other codes i dont want  and only keep the URL

 

 

this may have to be done using "regex" im not sure as i dont know to much about regex and what it can do but does sound like it would help lol

 

Link to comment
Share on other sites

http://www.phpf1.com/tutorial/get-current-page-url.html

 

that link might help you, you need to use the $_SERVER to get the content you need.

 

that not the type of URL im trying to get :D lol

 

here is a youtube embed

<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/cr19U8TVJtw?fs=1&hl=en_US&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/cr19U8TVJtw?fs=1&hl=en_US&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>

 

what im trying to grab is

http://www.youtube.com/v/cr19U8TVJtw?fs=1&hl=en_US&rel=0

but i dont want anything before this and dont want the "?" and all that other things pass that

 

so what im asking is how would i grab just

http://www.youtube.com/v/cr19U8TVJtw

 

 

Link to comment
Share on other sites

I made a function to do that, or can use anything would want from in it if looks at the values and remove/include the parts like you want them

 

see the post here, also look at the one below it

http://www.phpfreaks.com/forums/php-coding-help/getting-the-path/msg1506898/#msg1506898

 

php has a built in parse_url function

http://www.php.net/manual/en/function.parse-url.php

Link to comment
Share on other sites

<?php
function removeQuery($insert_link){
$query_parse_url = parse_url($insert_link, PHP_URL_QUERY);
$new_link = str_replace("?$query_parse_url",'',$insert_link);
return $new_link;
}
?>
<?php
//usage
$url = removeQuery("http://www.youtube.com/v/cr19U8TVJtw?fs=1&hl=en_US&rel=0");
echo $url;
?>

Link to comment
Share on other sites

ty you QuickOldCar and Sorry for wasting your time I believe i may have found a better way for me to do it it may not be as cool as your coding :D but it gets the job done lol

plus was having a hard time trying to find out how your worked :D

if there was a way to rank you up i would

 

Im not to sure how or why this code works but it does lol

i give it a youtube embed and it gives me back http://i2.ytimg.com/vi/cr19U8TVJtw/default.jpg what is what i wanted

if (preg_match("#http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#i", "$video_url")) {
$pre_regex = '#<object[^>]+>.+?'.
'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s';
$pre_replace = 'http://i2.ytimg.com/vi/\1/default.jpg';
$try9=preg_replace($pre_regex, $pre_replace, $video_url);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.