• Problem
    I run a music-blog and my authors copy links to the creative commons music mp3s directly in the post. Now, I want to extract these links to generate a special m3u-playlist. Therefore I made a new page and a new page template. Unfortunately I am no php-expert and after 4 hours I am quite frutstrated. I have a php-script which extracts the links, but now, I don’t know how to show them.

    Script

    <?php /* Template Name: Netaudio Player Page */ ?>
    
    <?php query_posts('cat=106&showposts=1'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php
    $content = get_the_content('');
    
    function pc_link_extractor($s) {
      $a = array();
      if (preg_match_all('/<a\s+.*?href=[\"\']?([^\"\' >]*)[\"\']?[^>]*>(.*?)<\/a>/i',
                         $s,$matches,PREG_SET_ORDER)) {
        foreach($matches as $match) {
          array_push($a,array($match[1],$match[2]));
        }
      }
      return $a;
    }
    
    $a = pc_link_extractor($content);
    print_r($a);
    
    endwhile; endif; ?>

    this gives me a wonderful list, with quite good results. but what now?

Viewing 1 replies (of 1 total)
  • Thread Starter phlow

    (@phlow)

    I solved it with some luck. The following code extracts from category with id 106 the links to the mp3s from the last 5 entries. now it’s very easy to build huge download-lists or m3u-lists. hopefully someone can use this.

    <?php /* Template Name: MP3 Links Page */ ?>
    <?php
    
    function pc_link_extractor($s) {
      $a = array();
      if (preg_match_all('/<a\s+.*?href=[\"\']?([^\"\' >]*).mp3[\"\']?[^>]*>(.*?)<\/a>/i',
                         $s,$matches,PREG_SET_ORDER)) {
        foreach($matches as $match) {
          echo '<a href="' . $match[1] . '.mp3">' . $match[2] . '</a><br />' . "\n"  ;
        }
      }
      return $a;
    }
    
    // mp3 category = 106
    query_posts('cat=106&showposts=5');
    if (have_posts()) : while (have_posts()) : the_post();
    
    $content = get_the_content();
    $a = pc_link_extractor($content);
    
    endwhile; endif;
    
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘How to extract links to mp3s from an entry to make a playlist?’ is closed to new replies.