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
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:
you could change my sample code from using
explode($song)tojson_decode($song, true)and have a nice keyed array to work with.Either way, I went with using the
strtokfunction 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
{}asstrtokremoves the tokens it is searching by.