我刚刚完成,你的帮助是有用的! :-)
这是我可以感兴趣的那些丑陋的代码。它没有漂亮的编码,而不是用来被加载每天这么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表中的记录条目完成,并确保当网站发生变化时,我可以不时加载脚本...保留现有翻译,覆盖现有文件等...没有问题那。
感谢收益,本网站真的很有帮助! :-)
嗨安德鲁, 所以我的正则表达式必须搜索('和')之间的内容?我必须尝试这个,将问题标记为回答如果它工作,谢谢! :-) – 2012-03-11 22:50:07
叶。我会让它在l('和')之间搜索。像/l\\('(.*?)'\\)/smi – 2012-03-12 07:33:34