我有一个带有 svn diff 的文件,我希望从 diff 中提取文件名。 如何为此编写解析器..
Index: libs/constant.php
===================================================================
--- libs/constant.php (revision 1243)
+++ libs/constant.php (revision 1244)
@@ -26,5 +26,5 @@
// changesss
-
+// test 2
?>
\ No newline at end of file
Index: libs/Tools.php
===================================================================
--- libs/Tools.php (revision 1243)
+++ libs/Tools.php (revision 1244)
@@ -34,5 +34,5 @@
// another file an change
-
+// test
?>
\ No newline at end of file
示例输出。
libs/constant.php
libs/Tools.php
编辑: 文件名可能不同 .php .inc .. 等等。 如何用 PHP 和 C 编写解析器。
最佳答案
使用 php 尝试此代码。
<?php
$fh = fopen('file.txt','rb');
for ($line = fgets($fh); ! feof($fh); $line = fgets($fh)) {
if ( preg_match( '/^(Index\:)(.*\.php)$/',$line ,$val ) )
{
print "$val[2]\n" ;
}
}
fclose($fh);
?>
Output: libs/constant.php libs/Tools.php
关于php - 使用 PHP 和 C 从 svn diff 文件获取文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2460200/