Need a preg_replace ninja!
I have this tag:
And I need it to be be automagically transformed into something like this:
I have looked at some of the YouTube expressions SirNot and Bergmot did, but I can't get them to work for this example.
Thanks for your time.
<mp3 src="myfile.mp3" title="my title" />And I need it to be be automagically transformed into something like this:
<object><param name="movie" value="player.swf?src=myfile.mp3&title=my-title"></param><embed src="player.swf?src=myfile.mp3&title=my-title" type="application/x-shockwave-flash"></embed></object>
I have looked at some of the YouTube expressions SirNot and Bergmot did, but I can't get them to work for this example.
Thanks for your time.
0
This discussion has been closed.
Comments
http://1976design.com/blog/archive/site-news/2004/07/29/redesign-tag-transform/
HTH
Martin.
$String = preg_replace('!<mp3 src="(.*?)" title="(.*?)" />!ie', '<object><param name="movie" value="player.swf?src=$1&title=$2"></param><embed src="player.swf?src=$1&title=$2" type="application/x-shockwave-flash"></embed></object>', $String);I came up with that, but, I have no idea how to make it into an extension now to test it.
Ideally, I would like it to work regardless of the post format (text, html, bbcode, etc.).
Can anyone help with that now?
sweeny, that really helped!
class Mp3Replace extends StringFormatter { function Parse($String, $Object, $FormatPurpose) { if($FormatPurpose == FORMAT_STRING_FOR_DISPLAY) { return preg_replace_callback( '/<mp3\s+src\s*=\s*(["\']?)(.+?)\\1\s+title\s*=\s*(["\']?)(.+?)\\3[^>]*>/si', create_function( '$m', '$url = \'player.swf?src=\'.urlencode($m[2]).\'&title=\'.urlencode($m[4]);'. 'return \'<object><param name="movie" value="\'.$url.\'" />'. '<embed src="player.swf?\'.$url.\'" '. 'type="application/x-shockwave-flash"></embed></object>\';' ), $String ); } else return $String; } } $Mp3Replace = $Context->ObjectFactory->NewContextObject($Context, 'Mp3Replace'); $Context->StringManipulator->AddGlobalManipulator('Mp3Replace', $Mp3Replace);or something to that effect...