Parsing m3u from single column to two equal columns


  • To parse a m3u file in a single column we have this.

    Display the content..

    <?php
    	require("parseshow_m3u.php");
    ?>
    <?php outputPlaylist('/ezstream/cvshows/playlist.m3u');?>
    

    Parse the content..

    <?php
    
    function outputPlaylist($playlist) {
    	$entries = parse_m3u($playlist);
    	echo "<pre>\n";
    	foreach($entries as $entry) {
    		printf("\"%s\"\n", $entry['title'], $entry['artist']);
    		
    	}
    	echo "</pre>";
    }
    
    ?>
    

    How would we make two equal columns out of this by modifying <pre></pre> in a styled div?



  • got it going and works just fine with some minor adjustments to fit the application.
    demo

    function outputPlaylist($playlist) {
    	$entries = parse_m3u($playlist);
    	echo "<div class='row'>\n";
    		echo "<pre>\n";
    		$size = sizeof($entries);
            $size_half = ceil($size / 2);
            $counter = 0;
    			echo "<div class='row'>\n";
    				echo "<div class='column'>\n";
    	foreach($entries as $entry) {
    		// Check for half way point
                         if($counter++ == $size_half ){
                                 // Close column and open new one
    				echo "</div>\n";
                         }
    						printf ("%s\n", $entry['title'], $entry['artist'] );
    		
    	}
    	// Close column and row
    			echo "</div>\n";
    		echo "</pre>";
    	echo "</div>\n";
    }
    ?>
    


  • @MPG-Radio

    I assume you want $entry['title'] and $entry['artist'] to show up in two columns?

    How does it look like now?



  • like so...http://mpg.dnset.com/radio/cvshows/showlist.php
    "Chuck Vans Show 19.10.20"
    "Chuck Vans Show 19.10.7"
    "Chuck Vans Show 19.10.8"
    "Chuck Vans Show 19.11.1"
    "Chuck Vans Show 19.11.14"
    "Chuck Vans Show 19.11.21"
    "Chuck Vans Show 19.11.29"
    "Chuck Vans Show 19.12.15"
    "Chuck Vans Show 19.12.9"
    "Chuck Vans Show 19.6.18"
    "Chuck Vans Show 19.6.25"
    "Chuck Vans Show 19.7.2"
    "Chuck Vans Show 19.7.9"
    "Chuck Vans Show 19.9.26"
    "Chuck Vans Show 19.9.5"



  • @MPG-Radio said in Parsing m3u from single column to two equal columns:

    <?php

    function outputPlaylist($playlist) {
    $entries = parse_m3u($playlist);
    echo "<pre>\n";
    foreach($entries as $entry) {
    printf(""%s"\n", $entry['title'], $entry['artist']);

    }
    echo "</pre>";
    }

    ?>

    @MPG-Radio

    Let's hope I understood your question. You want to split the content into two equal parts and place them in separate columns? If so I would try something like the following.

    <?php
    
    function outputPlaylist($playlist) {
    	$entries = parse_m3u($playlist);
    	echo "<pre>\n";
    
            $size = sizeof($entries);
            $size_half = ceil($size / 2);
            $counter = 0;
            echo "<div class='row'>\n"
            echo "<div class='column'>\n"
    
    	foreach($entries as $entry) {
                        // Check for half way point
                         if($counter++ == $size_half ){
                                 // Close column and open new one
                                 echo "</div>\n";
                                 echo "<div class='column'>\n";
                             }
                          // Insert content here 
                         printf(""%s"\n", $entry['title'], $entry['artist']);
    	}
             // Close column and row
             echo "</div>\n";
             echo "</div>\n";
           
    	echo "</pre>";
    }
    
    ?>
    

    CSS:

    /* Create two equal columns that floats next to each other */
    .column {
      float: left;
      margin: 30px;
    }
    
    /* Clear floats after the columns */
    .row:after {
      content: "";
      display: table;
      clear: both;
    }
    

    An CSS, HTML example can be found here: https://www.w3schools.com/code/tryit.asp?filename=GE6EM1SB78K8

    I hope that is what you had in mind. The code above has not been tested. Just fyi.



  • got it going and works just fine with some minor adjustments to fit the application.
    demo

    function outputPlaylist($playlist) {
    	$entries = parse_m3u($playlist);
    	echo "<div class='row'>\n";
    		echo "<pre>\n";
    		$size = sizeof($entries);
            $size_half = ceil($size / 2);
            $counter = 0;
    			echo "<div class='row'>\n";
    				echo "<div class='column'>\n";
    	foreach($entries as $entry) {
    		// Check for half way point
                         if($counter++ == $size_half ){
                                 // Close column and open new one
    				echo "</div>\n";
                         }
    						printf ("%s\n", $entry['title'], $entry['artist'] );
    		
    	}
    	// Close column and row
    			echo "</div>\n";
    		echo "</pre>";
    	echo "</div>\n";
    }
    ?>