SnakZ Posted January 28, 2011 Share Posted January 28, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/225908-how-find-a-line-replace-it-and-return-just-that-change-line/ Share on other sites More sharing options...
tomtimms Posted January 28, 2011 Share Posted January 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/225908-how-find-a-line-replace-it-and-return-just-that-change-line/#findComment-1166373 Share on other sites More sharing options...
SnakZ Posted January 28, 2011 Author Share Posted January 28, 2011 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 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 Quote Link to comment https://forums.phpfreaks.com/topic/225908-how-find-a-line-replace-it-and-return-just-that-change-line/#findComment-1166375 Share on other sites More sharing options...
QuickOldCar Posted January 28, 2011 Share Posted January 28, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/225908-how-find-a-line-replace-it-and-return-just-that-change-line/#findComment-1166378 Share on other sites More sharing options...
QuickOldCar Posted January 28, 2011 Share Posted January 28, 2011 <?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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/225908-how-find-a-line-replace-it-and-return-just-that-change-line/#findComment-1166381 Share on other sites More sharing options...
SnakZ Posted January 28, 2011 Author Share Posted January 28, 2011 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 but it gets the job done lol plus was having a hard time trying to find out how your worked 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); } Quote Link to comment https://forums.phpfreaks.com/topic/225908-how-find-a-line-replace-it-and-return-just-that-change-line/#findComment-1166412 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.