/
recomment.php
53 lines (44 loc) · 968 Bytes
/
recomment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/* Remove comments from a program*/
$handle = @fopen("redis-2.6.17/src/intset.c", 'r');
if (!$handle)
{
echo "Open file error\n";
exit;
}
while (($v = fgetc($handle)) !== false)
delcomment($v, $handle);
fclose($handle);
function delcomment($v1, $handle)
{
if ($v1 == '/')
{
$v2 = fgetc($handle);
if ($v2 == '*')
{
delmulitLine($handle);
}
else if ($v2 == '/')
{
fgets($handle);
}
else
{
echo $v1 . $v2;
}
}
else
{
echo $v1;
}
}
function delmulitLine($handle)
{
$c1 = fgetc($handle);
$c2 = fgetc($handle);
while (($c1 != '*') || ($c2 != '/'))
{
$c1 = $c2;
$c2 = fgetc($handle);
}
}