Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用PCRE的音频HTML代码_Php_Html_Regex_Pcre - Fatal编程技术网

Php 使用PCRE的音频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

我有一个函数在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/'.$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
。你的代码是错误的。