我有一个配置文件,我在其中存储所有字符串以便于引用并使翻译更容易 - 以防万一我需要将我的应用程序部署到我们的国际地点之一。
我想从 HTML 和 PHP 代码中删除我的硬编码字符串。
This site显示 IntelliJ IDEA 能够突出显示硬编码字符串。但是,我在我的 PhpStorm 2017.2 安装中看不到这样的选项。
这是 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 代码也是如此。
如果有任何兴趣,下面是我通常如何从我的配置数组中检索字符串。
/**
* 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/