Search code examples
phphtmlhref

Not Playing indirect link, however direct link is working


I've got this code and it works with the direct links. I've even got the parser working, so it pulls the free2viewtv list, however when i click on one of the links created using the parser, it doesnt work..

However if i click on 247 Retro TV, that works perfectly, i know thats due to the 247 Retro TV being the direct link.

But for the life of me, i just cannot see what is going wrong with

    <li>
       <a class="chlist" data-value="<?php echo $item['tvmedia']; ?>" href="javascript:void(0)";><?php echo $item['tvtitle']; ?></a>
    </li>

This is the full php.

    <?php
require_once 'parser-Free2ViewTV.php';
require_once 'config.php';
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <h5 class="glow"><a href="Livestreams.php"></i>Free 2 View Web Player</h5></a>
    <script type="text/javascript" src="list.min.js"></script>
    <script type="text/javascript" src="jquery-3.6.0.min.js"></script>
     <script type="text/javascript" src="hls.js"></script>
    <link rel="stylesheet" href="player.css" media="all">
    <script src="player.js" async></script>

</head>
<body>
    <div id="videodiv">
             <video controls='none' id='myvideo' preload='none' tabindex='0'>
        <source id="primarysrc" src='none' type="application/x-mpegURL"/></video>
    </div>
    <div id="tvlist">
         <input  id="findfield" class="customSearch search" type="search" placeholder="find ..." />
<br>
      <ul id='playlist' class='list'>

<?php foreach ($items as $item) {?>
            <li><a class="chlist" data-value="<?php echo $item['tvmedia']; ?>" href="javascript:void(0)";><?php echo $item['tvtitle']; ?></a></li>
<?php } ?>

<li><a class='chlist' href='http://hlsdpi-cdn-chqtx02.totalstream.net/dpilive/247retro/ret/dai/playlist.m3u8'>247 Retro TV</a></li>
      </ul>
    </div>
  </body>
</html>

The Parser being used is:-

<?php
$m3ufile = file_get_contents('https://raw.githubusercontent.com/geonsey/Free2ViewTV/master/Free2ViewTV-2020-Remote.m3u');
$m3ufile = str_replace('group-title', 'tvgroup', $m3ufile);
$m3ufile = str_replace('.ts', '.m3u8', $m3ufile);
$m3ufile = str_replace("tvg-", "tv", $m3ufile);
$re = '/#EXTINF:(.+?)[,]\s?(.+?)[\r\n]+?((?:https?|rtmp):\/\/(?:\S*?\.\S*?)(?:[\s)\[\]{};"\'<]|\.\s|$))/';
$attributes = '/([a-zA-Z0-9\-]+?)="([^"]*)"/';
preg_match_all($re, $m3ufile, $matches);
$i = 1;
$items = array();
 foreach($matches[0] as $list) {
   preg_match($re, $list, $matchList);
   $mediaURL = preg_replace("/[\n\r]/","",$matchList[3]);
   $mediaURL = preg_replace('/\s+/', '', $mediaURL);
   $newdata =  array (
    'id' => $i++,
    'tvtitle' => $matchList[2],
    'tvmedia' => $mediaURL
    );
    preg_match_all($attributes, $list, $matches, PREG_SET_ORDER);
    foreach ($matches as $match) {
       $newdata[$match[1]] = $match[2];
    }
     $items[] = $newdata;
 }
?>

I also tried

<li><a class="chlist" data-value="<?php echo $item['tvmedia']; ?>" href=$item['tvmedia'];><?php echo $item['tvtitle']; ?>

However the $item['tvmedia']; doesnt put the link into href


Solution

  • You need to put the href value in quote marks and echo the value with PHP (just like you echo other values) e.g.

    href="<?php echo $item['tvmedia']; ?>"
    

    That's assuming $item['tvmedia'] contains a valid URL, of course :-)