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 360479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:29:33+00:00 2026-05-12T12:29:33+00:00

Hi I have placeholder text in my content from the CMS like this: $content

  • 0

Hi I have placeholder text in my content from the CMS like this:

$content = "blah blah blah.. yadda yadda, listen to this:
{mediafile file=audiofile7.mp3}
and whilst your here , check this: {mediafile file=audiofile24.mp3}"

and i need to replace the placeholders with some html to display the swf object to play the mp3.

How do i do a replace that gets the filename from my placeholder.

I think the regx pattern is {mediafile file=[A-Za-z0-9_]} but then how do i apply that to the whole variable containing the markers?

Thanks very much to anyone that can help,

Will

  • 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-12T12:29:33+00:00Added an answer on May 12, 2026 at 12:29 pm

    I originally was thinking you could use a function that involved json_decode, but strings need to be wrapped in quotes or json_decode doesn’t handle them. So if your placeholders were written:

    {"mediafile" : "file" : "blahblah.mp3"}
    

    you could change my sample code from using explode($song) to json_decode($song, true) and have a nice keyed array to work with.

    Either way, I went with using the strtok function to find the placeholders, and then a basic string replace function to change the instances of the found placeholders into html, which is just gibberish.

    strtok, so far as PHP docs indicate, does not use regex, so this would be not only simpler but also avoid a call to the preg library.

    One last thing. If you do go with json syntax, you will have to re-wrap the placeholders in{} as strtok removes the tokens it is searching by.

    <?php
    $content = "blah blah blah.. yadda yadda, listen to this:
    {mediafile file=audiofile7.mp3}
    and whilst your here , check this: {mediafile file=audiofile24.mp3}";
    
        function song2html($song) {
           $song_info = explode("=", $song);
           $song_url = $song_info[1];
           $song_html = "<object src=\"$song_url\" blahblahblah>blah</object>";
        return ($song_html);
        }
    
    $tok = strtok($content, "{}");
    
    while ($tok !== false) {
        if(strpos($tok, "mediafile") !== false) {
      $songs[] = $tok;
     }
     $tok = strtok("{}");
    }
    
    foreach($songs as $asong) {
     $content = str_replace($asong, song2html($asong), $content);
    }
    
    echo $content;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a perl script that's reading an INI file like this: [placeholder_title] Hostname
Suppose I have a body of text (string) like this: str = 'This is
I have 4 content placeholder from my master page and I am using the
I have an input field which has a placeholder text. I want one word
I have researched how to manually include a PlaceHolder Text in UITextView (as there
I have picked up this code(DragandDrop.jsp) from this page :: http://jsfiddle.net/petersendidit/S4QgX/ I am getting
I have an edit page that fills the content with the original content from
I have honestly tried several different avenues from google on this erro but I
I have a page with a placeholder content block. Once the page is loaded
I have a question about jQuery UI Dialog boxes and showing dynamic content from

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.