Php 使用PCRE的音频HTML代码
我有一个函数在HTML文件中使用音频Php 使用PCRE的音频HTML代码,php,html,regex,pcre,Php,Html,Regex,Pcre,我有一个函数在HTML文件中使用音频 function html_code_for_audio($audio_file_location) { $extension=strtolower(substr(strrchr($audio_file_location, '.') ,1)); $html_code= '<audio controls> '. '<source src="'.$audio_file_location.'" type="audio
function html_code_for_audio($audio_file_location)
{
$extension=strtolower(substr(strrchr($audio_file_location, '.') ,1));
$html_code=
'<audio controls> '.
'<source src="'.$audio_file_location.'" type="audio/'.$extension.'" >'.
'Your navigator is not well equipped to display audio files</audio>';
return($html_code);
}
函数html\u-code\u用于音频($audio\u-file\u-location)
{
$extension=strtolower(substr(strrchr($audio_file_location')),1);
$html\U代码=
' '.
''.
“您的导航器没有很好的设备来显示音频文件”;
返回($html_代码);
}
我想知道这个代码片段是否可以使用PCRE函数进行改进/缩短;比如:
$html_code=
preg_replace('`(.+)\.(.+)`',
'<audio controls> '.
'<source src="$1.$2" type="audio/$2">'.
'Your navigator is not well equipped to display audio files</audio>'
, $audio_file_location);
$html\u代码=
preg_replace('`(+)\.('++)`',
' '.
''.
“您的导航器没有很好的设备来显示音频文件”
,$audio\u file\u location);
可能吗?请注意
.mp3
的MIME类型是音频/mpeg
,而不是音频/mp3
。你的代码是错误的。