Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:00:47+00:00 2026-05-30T18:00:47+00:00

I have a playlist script in my wordpress theme that puts the URL from

  • 0

I have a playlist script in my wordpress theme that puts the URL from a file in the media gallery into a playlist script that can be read by the audio player.

<script type="text/javascript">
var myPlaylist = [
 <?php
 foreach ($audiofiles as $file)
 {
   echo "{
        mp3:'".$file->guid."',
        title:'".$file->post_title."',
        artist:'"."',
        rating:5,
        buy:'".$file->post_excerpt."',
        price:'"."',
        duration:'"."',
        cover:'"."'
    },"
; }
?>
];
</script>

My problem is that I need to figure out how to change the output of the php script on the LAST item, so that there is no comma after the “}”. I’ve been told this is an AJAX problem, but I’m not sure where to begin.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:00:49+00:00Added an answer on May 30, 2026 at 6:00 pm

    When passing objects from PHP to JS, the safest, simplest way is to use json_encode. This way you won’t have to worry about breaking your JS syntax in case $file->post_title contains ' or any other character that would break it.

    <?php
     $playlist = array();
     foreach ($audiofiles as $file)
     {
       $playlist[] = array(
            'mp3'=>$file->guid,
            'title'=>$file->post_title,
            'artist'=>'',
            'rating'=>5,
            'buy'=>$file->post_excerpt,
            'price'=>'',
            'duration'=>'',
            'cover'=>''
        );
      }
    ?>
    
    <script type="text/javascript">
      var myPlaylist = <?= json_encode($playlist) ?>;
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing xml document with music playlist information, which is read into
I have a client that wants to be able to select from a playlist
I have a GDATA link that contains a playlist from a public YouTube Channel.
I have a live radio streaming playlist url, when I open that url in
Say, I have an array that looks like this: var playlist = [ {artist:Herbie
I have to make an application that stream a playlist in the ITU-R BT.656
I have created an XSPF playlist of songs that I need to copy to
I have a page that loads a playlist of songs. The individual songs in
I have a model for a Playlist object that has a number of Tracks.
I have implemented a flowplayer plugin into my website , with playlist and control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.