Good morning everyone, from the internet, I download a text file that contains many links to TV shows and movies streaming channels, but it is presented in a random order, there is a way in php for reordering each line according to an order that I can set I perhaps through an array or something? This is an example of how compound and the file to which would give a different order, using the name of the channel tv, being the only source that changes in all rows. They are a beginner and are days I look for in network how to do, but I can not find examples that make my case. Thank you.
<a href='http://example.com:80/tv/example/playlist.m3u8'>AdamTV</a>
<a href='http://example.com:80/tv/example/playlist.m3u8'>Skynews</a>
<a href='http://example.com:80/tv/example/playlist.m3u8'>NaturalTV</a>
<a href='http://example.com:80/tv/example/playlist.m3u8'>SportTV</a>
<a href='http://example.com:80/tv/example/playlist.m3u8'>Channel4</a>
This is what I'm trying to do, start reading the file line by line, but I error Deprecated: Function split () is deprecated
<?php
$linee = file("file.txt");
while(list(,$value) = each($linee)) {
list($url, $channel) = split("[>]", $value);
$params["url"] = trim($url);
$params["channel"] = trim($channel);
echo $params["url"]." ".$params["channel"];
}
Read file into array and then sort the array with usort - this will allow to you extract a TV show name from a link (for example, with preg_match
) and compare them.
Example:
$linee = [
"<a href='http://example.com:80/tv/example/playlist.m3u8'>AdamTV</a>",
"<a href='http://example.com:80/tv/example/playlist.m3u8'>Skynews</a>",
"<a href='http://example.com:80/tv/example/playlist.m3u8'>NaturalTV</a>",
"<a href='http://example.com:80/tv/example/playlist.m3u8'>SportTV</a>",
"<a href='http://example.com:80/tv/example/playlist.m3u8'>Channel4</a>",
];
usort(
$linee,
function($a, $b) {
preg_match("/>(.*)</", $a, $a_val);
preg_match("/>(.*)</", $b, $b_val);
if ($a_val[0] == $b_val[0]) {
return 0;
}
return ($a_val[0] < $b_val[0]) ? -1 : 1;
}
);
print_r($linee);