1

I have two different torrent scrapping classes and I want to combine them, they are working fine separately but the only problem is, when I convert my string into an array, it does not work.

That's the codes I am using so far.

<?php
require 'scraper.php';
require 'tor-info.php';

$scraper = new Scrapeer\Scraper();
$torrent = new Torrent( './test.torrent' );

$hashix = $torrent->hash_info();
var_dump($torrent->scrape()); // shows trackers list like this array(21) { ["udp://tracker4.piratux.com:6969/announce"]=> bool(false) ["udp://tracker.trackerfix.com:80/announce"]=> bool(false) ["udp://tracker.pomf.se:80/announce"]=> bool(false) ["udp://torrent.gresille.org:80/announce"]=> bool(false) so on..

$trackers = array( "udp://tracker4.piratux.com:6969/announce", "udp://tracker.trackerfix.com:80/announce", "udp://tracker.pomf.se:80/announce" ); // now here we need that trackers list
$hash = array( $hashix );
$info = $scraper->scrape( $hash, $trackers );

//print_r( $info );

echo '<br><hr>';

foreach ($info as $key => $value) {
echo 'SEEDS :' .$value['seeders'].'<br />';
echo 'LEECHES :' .$value['leechers'].'<br />';
}

?>

In the first part I converted the array into String to get the readable result, and then in the second part I needed to convert that string back into single array to produce the result.

10
  • What does the recombining looks like? Commented Jun 12, 2017 at 12:37
  • I need to get recombining like this $trackers = array ("udp://tracker4.piratux.com:6969/announce","udp://tracker.trackerfix.com:80/announce") Commented Jun 12, 2017 at 12:40
  • It displays the result like this array ( 0 => '"udp://tracker4.piratux.com:6969/announce"', 1 => '"udp://tracker.trackerfix.com:80/announce"', 2 => '"udp://tracker.pomf.se:80/announce"' ) Commented Jun 12, 2017 at 12:45
  • yes, its the expected result the only problem is the Converting string back into single array, after it is converted into string Commented Jun 12, 2017 at 12:50
  • I need those to work like this $trackers = array($tracker); $hash = array($hashix); $info = $scraper->scrape( $hash, $trackers ); Commented Jun 12, 2017 at 12:56

2 Answers 2

1

Why don't you just make them an array to begin with?

<?php
require 'scraper.php';
require 'tor-info.php';

$scraper = new Scrapeer\Scraper();
$torrent = new Torrent( './test.torrent' );    
$hashix = $torrent->hash_info();
$trackers = array_keys($torrent->scrape());

$hash = array( $hashix );
$info = $scraper->scrape( $hash, $trackers );

echo '<br><hr>';

foreach ($info as $key => $value) {
   echo 'SEEDS :' .$value['seeders'].'<br />';
   echo 'LEECHES :' .$value['leechers'].'<br />';
}
Sign up to request clarification or add additional context in comments.

11 Comments

ok I have tried like this $trackerArray = []; foreach($torrent->scrape() as $trackx => $k) { $trackerArray[] = $trackx; } $tracker = '"'.implode('","',$trackerArray).'"'; $trackers = array($tracker); $info = $scraper->scrape( $hash, $trackers ); but still not working
@Aliza the point was to have the array since you needed it for $scaper->scrape($hash, $trackersArray); See the update.
Ok I have tried like this now $trackerArray = array_keys($torrent->scrape()); $tracker = '"'.implode('","',$trackerArray).'"'; $trackers = array($tracker); $hash = array('40e22987e52a8a90b2513792266905dae84cb29f'); $info = $scraper->scrape( $hash, $trackers ); but still doesn't work
I don't think I can help you.
It works like this, $trackers = array("udp://tracker4.piratux.com:6969/announce","udp://tracker.trackerfix.com:80/announce"); $hash = array('40e22987e52a8a90b2513792266905dae84cb29f'); $info = $scraper->scrape( $hash, $trackers ); but when we use that string into a single array, it does not work, and i need to convert that string into an array, because that string is dynamic
|
0

Since your string looks like this (from comment) : "udp://tracker4.piratux.com:6969/announce","udp://tracker.trackerfix.com:80/announce" you could use PHP's explode() function like so:

$recombined = explode(',', str_replace('"', '', $trackers));

1 Comment

thanks for your kind response, but if I don't use quotes around the string, it does not work in the array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.