Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 YouTube profile ID regex
Zenk Offline
Junior Member
**
Posts: 27
Joined: Nov 2011
Post: #1
YouTube profile ID regex
Hi guys, could you help me sort out the YouTube IDs?
Unfortunately YouTube now offers custom IDs to people with 500 min. subscribers only, so I am forced to allow the long weird URLs on my forum as well.

At the moment I have this regex:

PHP Code:
((http|https):\/\/|)(www\.)?youtube\.com\/(channel\/|user\/)[a-zA-Z0-9]{1,}


Which allows - http/https +/ www:

Code:
youtube.com/channel/CoolUserName
youtube.com/user/CoolUserName
youtube.com/channel/xHsadRaNdOmLeTtErS_3-x
youtube.com/user/xHsadRaNdOmLeTtErS_3-x


But it would be amazing if someone could help me with doing it so that you can just enter the ID as well, eg:
http/https and/or www:

PHP Code:
1
2
3
4
5
6
7
youtube.com/user/CoolUserName - value 2
youtube.com/channel/CoolUserName - value 2
youtube.com/CoolUserName - value 2*
CoolUserName - value 1
youtube.com/user/xHsadRaNdOmLeTtErS_3-x - value 2
youtube.com/channel/xHsadRaNdOmLeTtErS_3-x - value 2
xHsadRaNdOmLeTtErS_3-x - value 1


*youtube.com/CoolUserName - optional.

So the display format would be: {VALUE$1}{VALUE$2}

Unless there is a way to just store the ID (value 1) from the entered URL into the database?

12-27-2014 09:48 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: YouTube profile ID regex
I'm not too sure how you'd differentiate between a channel and a user (is there a distinction?), but you could just simply take your existing regex and make the first part optional.

Code:
(?:((http|https):\/\/|)(www\.)?youtube\.com\/(channel\/|user\/))?[a-zA-Z0-9]{1,}


It's probably possible to just store the ID in the database if you make use of the input formatter (find the last '/' character and take everything from there).


My Blog
12-27-2014 10:38 AM
Find all posts by this user Quote this message in a reply
Zenk Offline
Junior Member
**
Posts: 27
Joined: Nov 2011
Post: #3
RE: YouTube profile ID regex
Thanks!

Code:
<if strpos($mybb->input['xthreads_kanaly'], 'youtube.com') !== false then>
substr(strrchr({VALUE}, '/'), 1)
<else>
{VALUE}
</if>


Will something like this work for Input Formatter?

@Edit: The if statement works, not sure how to trim the {VALUE}:

PHP Code:
substr(strrchr({VALUE}, '/'), 1)

(This post was last modified: 12-27-2014 11:18 AM by Zenk.)
12-27-2014 11:10 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: YouTube profile ID regex

Code:
substr({VALUE}, (strrchr({VALUE}, '/') ?: -1)+1)


My Blog
(This post was last modified: 12-27-2014 05:01 PM by ZiNgA BuRgA.)
12-27-2014 05:00 PM
Find all posts by this user Quote this message in a reply
Zenk Offline
Junior Member
**
Posts: 27
Joined: Nov 2011
Post: #5
RE: YouTube profile ID regex
It's not parsing for some reason, am I missing something?
[Image: k6aMIG9.png]

@Edit:
Nvm: Fixed

Code:
<?=substr(strrchr({VALUE}, '/'), 1)?>


@down:
Thanks Wink

(This post was last modified: 12-30-2014 01:26 AM by Zenk.)
12-27-2014 07:17 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #6
RE: YouTube profile ID regex
Oops, my mistake, should've been:

Code:
<?=substr({VALUE}, (strrpos({VALUE}, '/') ?: -1)+1)?>


My Blog
12-28-2014 02:59 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: