PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : (PHP) - Links filtern (gruppieren)



Uranjitsu
23.03.2017, 17:12
Grüßt euch,

hat jemand eine Idee wie ich Links aus einer Textarea filtern- und jeweile in einem array übergeben kann?

Beispiel Inhalt der textarea:



http://ul.to/1
http://ul.to/2
http://ul.to/3
http://ul.to/4
http://www.share-online.biz/1
http://www.share-online.biz/2
http://www.share-online.biz/3
http://www.share-online.biz/4


Somit sollen de ul.to zusammengefasst werden und die share-online links.
Diese möchte ich dann separat weiter verarbeiten und/oder getrennt in die Datenbank übergeben.

LG

FLX
23.03.2017, 17:26
$result = explode(PHP_EOL, $content);

Damit haste schonmal ein array mit Inhalt der einzelnen Zeilen ;)

Uranjitsu
23.03.2017, 18:56
Ja,
dass habe ich bereits, dennoch danke dafür.

Es geht ja darum die Links so zu filtern das ich Gruppe a und gruppe b habe.

a mit den ul- links
b mit den so- links

Das bekomme ich nicht gebacken. :/

- - - - - - - - - - Beitrag nachträglich erweitert - - - - - - - - - -

Hab da jetzt eine Variante gebastelt, aber kann mir jemand sagen ob das zuverlässig ist?


$content = '
http://ul.to/2
http://www.share-online.biz/2
http://ul.to/3
http://www.share-online.biz/4
http://ul.to/4
http://www.share-online.biz/1
http://www.share-online.biz/3
http://www.share-online.biz/4
http://ul.to/1
';

$result = explode(PHP_EOL, $content);

echo "Test1<br />";
foreach ($result as $url) {
$parse = parse_url($url);
if ($parse['host'] == "ul.to") {
$ul .= $url;
} elseif ($parse['host'] == "www.share-online.biz") {
$so .= $url;
}
}

echo "UL<br />";
echo $ul;
echo "<br />SO<br />";
echo $so;
echo "<br />";
var_dump($result);
echo "<br />";


Ausgabe:


Test2
UL
http://ul.to/2http://ul.to/3http://ul.to/4http://ul.to/1
SO
http://www.share-online.biz/2http://www.share-online.biz/4http://www.share-online.biz/1http://www.share-online.biz/3http://www.share-online.biz/4

array(11) {
[0]=>
string(0) ""
[1]=>
string(14) "http://ul.to/2"
[2]=>
string(29) "http://www.share-online.biz/2"
[3]=>
string(14) "http://ul.to/3"
[4]=>
string(29) "http://www.share-online.biz/4"
[5]=>
string(14) "http://ul.to/4"
[6]=>
string(29) "http://www.share-online.biz/1"
[7]=>
string(29) "http://www.share-online.biz/3"
[8]=>
string(29) "http://www.share-online.biz/4"
[9]=>
string(14) "http://ul.to/1"
[10]=>
string(0) ""
}

1stAid
23.03.2017, 20:58
2x regex?
1x mit ul
1x mit so
danach beide var zuasmmenführen?
als Plan B nach dem trennen ein sort
PHP: sort - Manual (http://php.net/manual/de/function.sort.php)

Grundsätzlich würde ich dazu neigen eine var oder einen Array pro OCH zu generieren, da die Weiterverabeitung je nach Anwendung pracktischer ist

Gruß

zerox
23.03.2017, 21:23
Das hier wird nicht immer funktionieren. "if ($parse['host'] == "ul.to") {"
Da Uploaded mehrer Domains hat und ul.to nur eine davon ist. Aber parse_url kannst du benutzen ist eine Lösung die man nehmen kann.

Grüße

Uranjitsu
24.03.2017, 00:14
Also ich bin jetzt so weit und habe mir diese funktion zum Test mal zusammengebaut.
An sich scheint das zu funktionieren und wäre dementsprechend auch erweiterbar.


function mirror_maker($ochlinks)
{

$array_in = explode(PHP_EOL, $ochlinks);
foreach ($array_in as $url) {
$parse = parse_url($url);
if ($parse['host'] == "ul.to") {
$ul1 .= $url;
} elseif ($parse['host'] == "uploaded.net") {
$ul2 .= $url . "\n";
} elseif ($parse['host'] == "www.share-online.biz") {
$so1 .= $url . "\n";
} elseif ($parse['host'] == "share-online.biz") {
$so2 .= $url . "\n";
} elseif ($parse['host'] == "rapidgator.net") {
$rg1 .= $url . "\n";
} elseif ($parse['host'] == "openload.co") {
$ol1 .= $url . "\n";
} elseif ($parse['host'] == "www.bigfile.to") {
$bf1 .= $url . "\n";
} elseif ($parse['host'] == "bigfile.to") {
$bf2 .= $url . "\n";
} elseif ($parse['host'] == "www.oboom.com") {
$ob1 .= $url . "\n";
} elseif ($parse['host'] == "oboom.com") {
$ob2 .= $url . "\n";
}
}
$uploaded = $ul1 . $ul2;
$shareonline = $so1 . $so2;
$rapidgator = $rg1;
$openload = $ol1;
$bigfile = $bf1 . $bf2;
$oboom = $ob1 . $ob2;

$array_out = array(
$uploaded,
$shareonline,
$rapidgator,
$openload,
$bigfile,
$oboom,
);
return ($array_out);
}

@1stAid,
mit RegEx tue ich mich immer ganz ganz schwer :P

1stAid
24.03.2017, 07:50
(ul\.to|uploaded\.net|(www\.)?share-?online\.biz|rapidgator\.net|openload\.co|(www\.)? bigfile.to|(www\.)?oboom\.com)
als singeline und ignorecase.
1 Zeile statt 1897x
https://regex101.com/r/AgFmpV/1

oder noch etwas kürzer
(www\.)?(ul\.to|uploaded\.net|share-?online\.biz|rapidgator\.net|openload\.co|bigfile\ .to|oboom\.com)
https://regex101.com/r/45pn45/1

oder noch etwas kürzer
(www\.)?(ul|uploaded|share-?online|rapidgator|openload|bigfile|oboom)\.(to|ne t|biz|com?)
https://regex101.com/r/6evKmh/2

Da die Hoster von links nach rechts abgearbeitet werden, kannst du dir die OCH nach Wunsch sortieren.
Gruß

Nimbus
24.03.2017, 13:22
Kennst du Switch? :D
Alternativ könntest du die Hoster auch ganz generisch gestalten, sodass deine Funktion mit allen Links funktioniert. Dazu könntest du z.B. die Links in einem Array ablegen und als Key den Hostname verwenden und daraus später die Liste erstellen.

EDIT: Also quasi so:

<?php
pretty_print( mirror_maker( "http://ul.to/1
http://ul.to/2
http://ul.to/3
http://ul.to/4
http://www.share-online.biz/1
http://www.share-online.biz/2
http://www.share-online.biz/3
http://www.share-online.biz/4" ) );

function mirror_maker( $ochlinks ) {
$array_in = explode( PHP_EOL, $ochlinks );
$array_out = array();

foreach ($array_in as $url) {
$host = parse_url($url)['host'];
if (!empty($url) && !empty($host)) {
$array_out[$host][] = $url;
}

}

return $array_out;
}

function pretty_print($array_in) {
foreach ($array_in as $hoster=>$link) {
echo "$hoster\n";
echo implode("\n", $link);
echo "\n\n";
}
}
?>

Uranjitsu
24.03.2017, 17:15
Danke für die Ideen :emoji41: