cip6791 Posted March 17, 2008 Share Posted March 17, 2008 Hello I m new and don't know what i m doing ... so please help me out. Let's say I wanted the first link to look like the second one when somebody embeds a video from youtube. How can I use php to take out the $color1 and $color2 ? Thank you. Link to comment https://forums.phpfreaks.com/topic/96573-using-php-to-delete-something-from-a-link/ Share on other sites More sharing options...
micah1701 Posted March 17, 2008 Share Posted March 17, 2008 i would split the original into an array then rebuild it from the parts you want. <?php $originalString = "http://www.youtube.com/v/GUHLa1qSy24&rel=0&color1=0x5d1719&color2=0xcd311b&hl=en"; $parts = explode("&",$originalString); $newString = $parts[0]; // newString = http://www.youtube.com/v/GUHLa1qSy24 $newString.= "&"; $newString.= array_pop($parts); //takes the last value of the array (in this case "hl=en") echo $newString; // returns: http://www.youtube.com/v/GUHLa1qSy24&hl=en ?> Link to comment https://forums.phpfreaks.com/topic/96573-using-php-to-delete-something-from-a-link/#findComment-494228 Share on other sites More sharing options...
TheUnknownCylon Posted March 17, 2008 Share Posted March 17, 2008 First explode the color1= part, it will be split up into 2 parts. Then split up on the &-mark, you've got the color tag. I guess this is the easiest way, not the best... <?php $url = 'http://www.youtube.com/v/GUHLa1qSy24&rel=0&color1=0x5d1719&color2=0xcd311b&hl=en'; $color1a = explode("color1=", $url); $color1b = explode("&", $color1a[1]); $color1 = $color1b[0]; $color2a = explode("color2=", $url); $color2b = explode("&", $color2a[1]); $color2 = $color2b[0]; echo $color1.'<br/>'; echo $color2.'<br/>'; ?> Link to comment https://forums.phpfreaks.com/topic/96573-using-php-to-delete-something-from-a-link/#findComment-494236 Share on other sites More sharing options...
cip6791 Posted March 17, 2008 Author Share Posted March 17, 2008 thanks for your help guys ... Link to comment https://forums.phpfreaks.com/topic/96573-using-php-to-delete-something-from-a-link/#findComment-494311 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.