0
我從shell_exec
輸出看起來像這樣:並非所有的文字被寫入到文件
0134d690 W ContainerSetContentPacket::getName() const
00d06f64 W ResourcePackDataInfoPacket::getId() const
00d06f80 W ResourcePackDataInfoPacket::write(BinaryStream&) const
00d0713c W ResourcePackDataInfoPacket::handle(NetworkIdentifier const&,
NetEventCallback&) const
00d06f68 W ResourcePackDataInfoPacket::getName() const
00bf510c W StructureBlockUpdatePacket::getId() const
00bf5128 W StructureBlockUpdatePacket::write(BinaryStream&) const
00bf52f0 W StructureBlockUpdatePacket::handle(NetworkIdentifier const&,
NetEventCallback&) const
和我想要寫的方法與類名的文件。如果你不知道我在說什麼,下面有一個例子:
ClassName::function()
ClassName::function2()
我還想寫function()
和function2()
到一個名爲ClassName.txt文件。現在我的代碼現在創建了所有文件並只添加了一個函數(getName()
)或上面的示例function()
但不是function2()
現在,這是一個問題。在寫入文件之前,當我在下面回顯$method
變量時,它顯示所有功能,但只寫入一個文件。
PHP代碼:
<?php
$out = trim(shell_exec("nm -DC *.so | grep 'Packet::'"));
$out = explode("\n", $out);
$out = array_filter($out, "trim");
foreach($out as $line) {
$line = explode(' ', $line, 2);
$class = substr($line[1], 0, strpos($line[1], "::"));
if(strpos($class, "std") === false and strpos($class, "void") === false
and strpos($class, "vtable") === false) {
$title = array_filter(explode("\n", substr($class, 2)), "trim");
}
foreach($title as $name) {
$function = substr($line[1], strpos($line[1], "::"));
$function = substr($function, 0, strpos($function, ")"));
if(strpos($function, "_") === false and strpos($function, "<") === false
and strpos($function, "+") === false
and strpos($function, "vtable") === false
and strpos($function, "void") === false) {
$method = str_replace("W", "", "void $function);");
$method = str_replace("T", "", $method);
$method = str_replace("::", "", $method);
}
file_put_contents("stuff/$name.txt", $method . PHP_EOL);
}
}