php - PhpStorm 是否有办法突出显示硬编码字符串?

标签 php html string intellij-idea phpstorm

我有一个配置文件,我在其中存储所有字符串以便于引用并使翻译更容易 - 以防万一我需要将我的应用程序部署到我们的国际地点之一。

我想从 HTML 和 PHP 代码中删除我的硬编码字符串。

This site显示 IntelliJ IDEA 能够突出显示硬编码字符串。但是,我在我的 PhpStorm 2017.2 安装中看不到这样的选项。

PhpStorm Settings

这是 HTML 中的一个示例,我想将其清除并替换为非硬编码字符串:

<thead>
<tr>
    <th class="text-center">#</th>
    <th>Benutzername</th>
    <th>Nachname</th>
    <th>Vorname</th>
    <th>E-Mail</th>
    <th>Rollen</th>
    <th></th>
</tr>
</thead>

但是,PhpStorm 不会突出显示硬编码字符串或建议任何修复。 PHP 代码也是如此。

error highlighting

如果有任何兴趣,下面是我通常如何从我的配置数组中检索字符串。

/**
 * Extract a string from the config file depending on its tag.
 *
 * @param string $tag The string to extract.
 *
 * @return mixed The string that was extracted. At least it should usually be a string, but it could also be
 *               something different, depending on the config.
 */
function get_string($tag)
{
    // Check the config file first.
    global $config;
    $string = $config['strings'][$tag];
    if (!isset($string)) {
        // The faulty tag can be found in the logfile.
        logfile("String Tag not found: " . $tag);
        $string = $tag;
    }

    return $string;
}

我只是将数组索引提供给函数并从配置数组中检索字符串。如果我需要国际化,我可以修改这个功能。

最佳答案

您可以使用“cmd + f”并搜索 >[a-z0-9],它可以很好地找到 HTML 标记结束和字符串开始的任何实例

关于php - PhpStorm 是否有办法突出显示硬编码字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45714008/

相关文章:

html - Knockout.js:将可见性绑定(bind)到 validationMessage

javascript - 使用 JavaScript 更改输入框

c - 如何使用 printf 打印非空终止字符串?

php - 如何在 PHP 中初始化一个空的关联数组?

php - Robots.txt 正在阻止 Google 访问 WordPress 网站

javascript - .NET 中的 HTML 和 JavaScript 解析器

string - 大小为 n 的最大重复子串

java - 编程新手 - ***更新*** 抛出 StringIndexOutOfBoundsException 的练习问题

php - 在 while 循环中获取当前帖子类别名称

php - whereBetween问题,返回错误记录