<?php
function parseAudio($message) {
$matches = [];
$s = preg_match('/\[audio (.*?)\]/', $message, $matches);
return str_replace($matches[0], "<audio controls><source src=\"{$matches[1]}\" type=\"audio/wav\"></audio>", $message);
}
echo parseAudio("Message with audio\n[audio records/1517754431.wav]");
?>