문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top