PhpStorm有办法突出显示硬编码的字符串吗?

时间:2017-08-16 12:49:51

标签: 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;
}

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

1 个答案:

答案 0 :(得分:0)

@axiac提供了不同的观点。

HTML本身基本上都是硬编码的字符串 - 标签等等。

PHP需要许多字符串才能工作。 $_GET[]$_POST[]和像$config['strings'][$tag]这样的数组索引就是一些例子。

如果PhpStorm要突出显示所有这些字符串,则必须手动将所有这些字符串排除在外。

正如@axiac所说:

  

您可以使用&#34;在文件中查找&#34;命令在PHP中查找字符串   脚本(搜索['"]并检查&#34; RegExp&#34;)但你可能会   被大量的字符串所淹没,其中许多是数组   密钥或其他字符串(分隔符,SQL查询),它们是   代码,而不是输出。