Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

bittorrent - Magnet links library for PHP

Does anyone here know of a magnet-URI-parser for PHP? To validate it, or maybe to extract some information from it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you only need the fields, here is a quick and dirty one liner:

$link = 'magnet:?xt=urn:btih:0eb69459a28b08400c5f05bad3e63235b9853021&dn=Splinter.Cell.Blacklist-RELOADED&tr=udp%3A%2F%2Ftracker.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337';

parse_str(str_replace('tr=','tr[]=',parse_url($link,PHP_URL_QUERY)),$query);

print_r($query);

Should yield:

 Array
 (
    [xt] => urn:btih:0eb69459a28b08400c5f05bad3e63235b9853021
    [dn] => Splinter.Cell.Blacklist-RELOADED
    [tr] => Array
        (
            [0] => udp://tracker.com:80
            [1] => udp://tracker.publicbt.com:80
            [2] => udp://tracker.istole.it:6969
            [3] => udp://tracker.ccc.de:80
            [4] => udp://open.demonii.com:1337
        )
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...