Jump to content

Tip: getting parameters from url.


Carlo84
 Share

Recommended Posts

Hi , all my apologizes if this is not the correct forum to post this.

But i whas just browsing around looking for some info about getting the download url for youtube videos and noticed most of the scripts are broken cause the urls are read in wrong.

When trying to read an urls parameters you cannot use stringbetween and the likes of that, using a function like that means you are looking for something between the parameter and the parameter after that.

Now the issue with PHP GET method is that there is no specific order in witch these parameters must be passed, so if the order is changed your script will break.

right an url with get parameters looks like http://Somedomain.com/somepage.php?FirstParameter=FirstResult&MoreParameters=MoreResults

So just split your sting to get all parameters.

Lets not forget about bookmarks neither. http://Somedomain.com/somepage.php?FirstParameter=FirstResult&MoreParameters=MoreResults#Bookmark

cause we dont want the last parameter to be corrupted cause some bookmark.

Heres an example on getting a video ID from a youtube url. but hey it works on any url.

Func getVidIDfromURL($url = "http://www.youtube.com/watch?v=da0eaiZ0CKw&feature=related")
    $url = StringSplit($url, "&?#")
    Local $VidID = ""
    Local $i = 1
    While $i < $url[0] + 1
        If StringLeft($url[$i], 2) = "v=" Then
            $url = StringSplit($url[$i], "=")
            If $url[0] = 2 Then $VidID = $url[2]
            ExitLoop
        EndIf
        $i = $i + 1
    WEnd
    If $VidID = "" Then
        Return SetError(1, 0, 0)
    Else
        Return $VidID
    EndIf
EndFunc   ;==>getVidIDfromURL

or heres an example without splitting the string twice.

Func getVidIDfromURL($url = "http://www.youtube.com/watch?v=da0eaiZ0CKw&feature=related")
    $url = StringSplit($url, "&?#")
    Local $VidID = ""
    Local $i = 1
    While $i < $url[0] + 1
        If StringLeft($url[$i], 2) = "v=" Then
            $VidID = StringReplace ($url[$i], "v=", "")
            ExitLoop
        EndIf
        $i = $i + 1
    WEnd
    If $VidID = "" Then
        Return SetError(1, 0, 0)
    Else
        Return $VidID
    EndIf
EndFunc   ;==>getVidIDfromURL
Link to comment
Share on other sites

See this Post , it can help you ! Posted Image

Thanks wakillon, i think i should have posted this in examples, instead of help and support.

Its just an problem i seen allot in peoples scripts on the forum and figured id post an example for getting url parameters.

Thanks anyways ;) havent seen yours yet, might be usefull making my player.

Link to comment
Share on other sites

A player !

So See this post for a youtube player ! Posted Image

haha you got it all :) your stuff works perfect ;)

Yes im trying to make it something similar to Media Player Classic. but then for youtube and with options to save video/audio. and m3u support.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...