2012-03-11 22 views
0

我在一个多语种的网站上创建了自己的l($text)函数。我使用它像这样在我的文档:如何在所有的php文件中扫描自定义函数的所有用法?

echo '<h1>' . l('Title of the page') . '</h1'; 
echo '<p>' . l('Some text here...') . '</p>'; 

我的问题是,有一个PHP脚本,我怎么能扫描所有我.php文件来捕获所有这个函数的用法,并列出使用到MySQL表中的所有参数? 当然,目标是不要忘记我的traduction文件中的任何句子。

我在谷歌或这里没有找到任何东西,所以如果你有任何想法,或需要更多的信息。

回答

0

我刚刚完成,你的帮助是有用的! :-)

这是我可以感兴趣的那些丑陋的代码。它没有漂亮的编码,而不是用来被加载每天这么10000次......

<?php 
// define a plain text document to see what appen on test 
header('Content-Type: text/plain; charset=UTF-8'); 

$dossier = 'pages/'; // folder to scan 
$array_exclude = array('.', '..', '.DS_Store'); // system files to exclude 
$array_sentences_list = array(); 

if(is_dir($dossier)) // verify if is a folder 
{ 
    if($dh = opendir($dossier)) // open folder 
    { 
     while(($file = readdir($dh)) !== false) // scan all files in the folder 
     { 
      if(!in_array($file, $array_exclude)) // exclude system files previously listed in array 
      { 
       echo "\n".'######## ' . strtoupper($file) . ' ##########'."\n"; 
       $file1 = file('pages/'.$file); // path to the current file 
       foreach($file1 AS $fileline) 
       { 
        // regex : not start with a to z characters or a (
        // then catch sentences into l(' and ') 
        // and put results in a $matchs array 
        preg_match_all("#[^a-z\(]l\('(.+)'\)#U", $fileline, $matchs); 

        // fetch the associative array 
        foreach($matchs AS $match_this) 
        { 
         foreach($match_this AS $line) 
         { 
          // technique of "I do not want to break my head" 
          if(substr($line, 0, 3) != "l('" AND substr($line, 0, 4) != " l('" AND substr($line, 0, 4) != ".l('") 
          { 
           // check if the sentence is not already listed 
           if(!in_array($line, $array_sentences_list)) 
           { 
            // if not, add it to the sentences list array and write it for fun ! 
            $array_sentences_list[] = $line; 
            echo $line . "\n"; 
           } 
          } 
         } 
        } 
       } 
      } 
     } 
     closedir($dh); 
    } 
} 
?> 

小型精密:我确实有逃避各种情况为: - > CSS:背景:网址(“图像。 JPG'); 和 - > jQuery:$(this).html('bla bla'); 所以这里就是为什么用正则表达式[^ A-Z(] :-)

它工作得很好,现在开始!只需稍后用mysql表中的记录条目完成,并确保当网站发生变化时,我可以不时加载脚本...保留现有翻译,覆盖现有文件等...没有问题那。

感谢收益,本网站真的很有帮助! :-)

1

你能:

  • 阅读所有* .PHP与水珠文件()
  • 然后用正则表达式来拉弦出来(的preg_match())
  • 串简单的mysql插入?

似乎够简单吗?

+0

嗨安德鲁, 所以我的正则表达式必须搜索('和')之间的内容?我必须尝试这个,将问题标记为回答如果它工作,谢谢! :-) – 2012-03-11 22:50:07

+0

叶。我会让它在l('和')之间搜索。像/l\\('(.*?)'\\)/smi – 2012-03-12 07:33:34

相关问题