我需要一个磁铁链接中的两个项目:
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
价值btih
:
0eb69459a28b08400c5f05bad3e63235b9853021
和第一个的价值udp
:
udp://tracker.com:80
如何用PHP做到这一点?
由于parse_url()在这种情况下无法帮助你必须使用正则表达式来解析字符串,然后进一步操作字符串以获取跟踪器.所以类似于:
.*?)&dn=(?.*?)&tr=(? .*?)$#', $string, $magnet_link); //0eb69459a28b08400c5f05bad3e63235b9853021 echo $magnet_link['hash']; //Splinter.Cell.Blacklist-RELOADED echo $magnet_link['filename']; /*[trackers] => 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 ) */ $magnet_link['trackers'] = explode('&', urldecode(str_replace('tr=','', $magnet_link['trackers']))); //so to get first tracker $magnet_link['trackers'][0]; ?>