PNewCode Posted January 25 Share Posted January 25 Hello. I have the following that works great for youtube links. I'm using this to show a thumbnail with the help of some other coding that works awesome. However there needs something added. I tried to alter this in many various way but I don't seem to get a grasp on how to split it up right to add to it. The following is what I have. $url = "$ytvideo1"; parse_str( parse_url( $url, PHP_URL_QUERY ), $vid ); preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match); $youtube_id = $match[1]; And it works for ALMOST all of the youtube links. However if I have one that is like Quote https://youtu.be/2_Oiitq30DQ?si=GwL-7Se5tbRvLrQu or https://youtu.be/tgIiqVVYzfM?si=-h3y1mAHjShvGZL8 Then it doesn't work. I tried to add the "si" in there in multiple ways but not sure how. This is the only type of link that is stumping me so far Any thoughts on how to alter what I have to make it work? PS, I know it's adding my examples as links. I'm sorry. I couldn't find how to add those without it auto linking. Quote Link to comment https://forums.phpfreaks.com/topic/317652-php-and-preg-match/ Share on other sites More sharing options...
Andou Posted January 25 Share Posted January 25 As far as it could be an error, try adding ini_set('display_errors', '1'); and error_reporting(E_ALL); at the top of your file. Also, regex101.com is a great website for debugging why the regex isn't working. It also has good documentation. Quote Link to comment https://forums.phpfreaks.com/topic/317652-php-and-preg-match/#findComment-1614400 Share on other sites More sharing options...
PNewCode Posted January 25 Author Share Posted January 25 @Andou thank you, however The regex I have now works. I'm not getting any errors. But it's not doing what it needs to do because some links are like the example I gave instead of the other types. the "si" part is what needs to be added and those are also more than 11 characters I looked up a lot of docs on regex and the link you gave too. But that will have to be for when I can learn from scratch instead of just adding to what I have. Though I fully plan to do that asap Quote Link to comment https://forums.phpfreaks.com/topic/317652-php-and-preg-match/#findComment-1614401 Share on other sites More sharing options...
PNewCode Posted January 25 Author Share Posted January 25 I found somewhere that someone used si=([\w_]*) so I tried to add that in what I have but zero luck with it. Quote Link to comment https://forums.phpfreaks.com/topic/317652-php-and-preg-match/#findComment-1614403 Share on other sites More sharing options...
PNewCode Posted January 25 Author Share Posted January 25 I tried to edit my original but the option wasn't there. So it looks like I just need to remove the ?si= and whatever is after that Quote Link to comment https://forums.phpfreaks.com/topic/317652-php-and-preg-match/#findComment-1614404 Share on other sites More sharing options...
PNewCode Posted January 25 Author Share Posted January 25 Nevermind. I'm WAY off my mark on what I need to do. Moderators, feel free to delete this thread. My original question isn't even close to what I thought I needed to do. My appologies yall Quote Link to comment https://forums.phpfreaks.com/topic/317652-php-and-preg-match/#findComment-1614405 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.