dou2347 2014-04-09 20:50 采纳率: 0%
浏览 13
已采纳

在.phtml文件中搜索文本

I'm looking for a way to search in a folder with .phtml files and 'scan' the files for words.

This what I have in my .phtml files (twig engine):

<span>{{ 'language'|trans }}</span>
<a href="#">{{ 'Settings'|trans }}</a>

I have multiple .phtml files with these translations in it.
Now I would like to scan all the files and search for the strings before the |trans .

Is there a way to do this? And could you give me a tip how to begin with this? Because I have no clue how to start with this.

  • 写回答

1条回答 默认 最新

  • douti19680318 2014-04-09 21:41
    关注

    As said there are more ways to do this. This is just one take on it, I'm not pretending this is the best way to do it (in fact, my preferred way would be totally different, including not using PHP).

    Use opendir() to create a list of files to scan. On the documentation page some examples are shown that are quite useful for your purpose. Loop through the files and get their contents using, for example, file_get_contents(). Then use preg_match_all() on that content to find the strings you want. An example regex, based on the content in question, would be /\{{2}\s*([^|]+)\|trans\s*\}{2}/i.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)