我在Mac上使用Visual Studio Code来处理WordPress应用程序.
有没有办法让Visual Studio代码识别HTML并在PHP文件中使用它的功能(主要是自动完成)?
我之前已经搜索过这个答案,但只是被告知转到Visual Studio代码设置: File >> Preferences >> User Settings
// Place your settings in this file to overwrite the default settings
{
// Configure file associations to languages (e.g. "*.extension": "html"). These have precedence over the default associations of the languages installed.
"files.associations": {"*.php": "html"}
}
Run Code Online (Sandbox Code Playgroud)
但这样做会让您失去所有PHP支持和自动完成功能.
我希望微软能够意识到PHP开发人员在创建应用程序/网站时通常会同时使用PHP和HTML.如果可能的话,我很乐意使用VS Code而不是华丽但昂贵的PHP风暴.
我正在尝试使用以下函数将标准 Youtube URL 转换为嵌入 URL:
<?php
$url = 'https://www.youtube.com/watch?v=oVT78QcRQtU';
function getYoutubeEmbedUrl($url)
{
$shortUrlRegex = '/youtu.be\/([a-zA-Z0-9_]+)\??/i';
$longUrlRegex = '/youtube.com\/((?:embed)|(?:watch))((?:\?v\=)|(?:\/))(\w+)/i';
if (preg_match($longUrlRegex, $url, $matches)) {
$youtube_id = $matches[count($matches) - 1];
}
if (preg_match($shortUrlRegex, $url, $matches)) {
$youtube_id = $matches[count($matches) - 1];
}
return 'https://www.youtube.com/embed/' . $youtube_id ;
}
getYoutubeEmbedUrl();
Run Code Online (Sandbox Code Playgroud)
但是,当运行它时,我收到以下错误:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function getYoutubeEmbedUrl()
Run Code Online (Sandbox Code Playgroud)
我不明白为什么当我只有一个并且我提供了它时我的参数太少了?