mercredi 21 décembre 2016

Check if Youtube ID is valid with ColdFusion

I want to check if Youtube Link/ID is valid. It should get me an answer with an if / else statement.

I tried this:

       <cfoutput>
            <cfset variables.key = "EUcaCKWk83Q">
            <cfset variables.headers = "https://www.youtube.com/oembed?format=json&url=http://www.youtube.com/watch?v=#variables.key#">

            <cfif (IsArray(#variables.headers#) ? ReMatch('(http:\/\/)(?:www\.)?youtu(?:be\.com\/(?:watch\?|user\/|v\/|embed\/)\S+|\.be\/\S+)',#variables.headers#) : false)>
                Correct Id!
            <cfelse>
                There is no video with that Id!
            </cfif>
        </cfoutput>

The ID in the example is correct and should output: "Correct ID!" But it displays always the else-statement.

Thank you for helping!

Aucun commentaire:

Enregistrer un commentaire