([^\[]+)\[/caption\]~', $sContents, $aMatches, PREG_SET_ORDER)) { echo " no caption found\n"; continue; } foreach ($aMatches as $aMatch) { $sCaption = sprintf("{%% include caption.html\n width='%d'%s\n image='%s'\n text='%s'\n%%}", $aMatch[1], empty($aMatch[1]) ? null : sprintf("\n image-width='%d'", $aMatch[1]), $aMatch[2], $aMatch[4]); $sContents = str_replace($aMatch[0], $sCaption, $sContents); } $sNewFile = sprintf('%s/%s', $sNewDir, $sBasename); $sNewContents = '---' . "\n" . yamlDump($aYaml) . '---' . "\n" . trim($sContents); file_put_contents($sNewFile, $sNewContents); echo " new file saved!\n"; } function yamlDump($aData) { return str_replace("'", null, Yaml::dump($aData, 4, 2)); }