需要帮助编写php脚本来生成文本文件

时间:2022-09-15 16:38:54

I am not a php expert at all.

我根本不是一个PHP专家。

I am working on a VOIP project and have to open a port range (10000 - 20000) in my virtual box. The issue is that there is no such option to do it all in once. It has to be done one by one using a command line:

我正在开发一个VOIP项目,必须在我的虚拟框中打开一个端口范围(10000 - 20000)。问题在于没有这样的选择可以一次完成。必须使用命令行逐个完成:

VBoxManage modifyvm "Elastix 4.0" --natpf1 "guestssh,udp,,10001,,10001"
VBoxManage modifyvm "Elastix 4.0" --natpf1 "guestssh,udp,,10002,,10002"
VBoxManage modifyvm "Elastix 4.0" --natpf1 "guestssh,udp,,10003,,10003"

and so on till I reach

等到我到达

VBoxManage modifyvm "Elastix 4.0" --natpf1 "guestssh,udp,,20000,,20000"

Can anybody help me with a php script that will generate a TXT file which will contain

任何人都可以帮助我使用php脚本生成一个包含的TXT文件

VBoxManage modifyvm "Elastix 4.0" --natpf1 "guestssh,udp,,10001,,10001"
to
VBoxManage modifyvm "Elastix 4.0" --natpf1 "guestssh,udp,,20000,,20000"

Thanks

4 个解决方案

#1


1  

 <?php
  $fp = fopen("outfile.txt", "w");
  for($x = 10000; $x<=20000; $x++){
      fprintf($fp , 'VBoxManage modifyvm "Elastix 4.0" --natpf1 "guestssh%d,udp,,%d,,%d"'."\n", $x - 9999, $x, $x);
  }
  fclose($fp);

#2


1  

* is made to help you with your questions, not to code for you.

*旨在帮助您解决问题,而不是为您编写代码。

Anyway,

$output = '';
for ($i = 10001; $i <= 20000; ++$i) {
    $output .= 'VBoxManage modifyvm "Elastix 4.0" --natpf1 "guestssh,udp,,' . $i . ',,' . $i . '"' . PHP_EOL;
}

$f = fopen('commands.txt', 'w');
fwrite($f, $output);
fclose($f);

#3


0  

This is a simple solution using file_put_contents() for printing the text you wrote to a file called "this_is_my_txt_file.txt".

这是一个简单的解决方案,使用file_put_contents()将您写入的文本打印到名为“this_is_my_txt_file.txt”的文件中。

file_put_contents('this_is_my_txt_file.txt', "VBoxManage modifyvm \"Elastix 4.0\" --natpf1 \"guestssh,udp,,10001,,10001\" to VBoxManage modifyvm \"Elastix 4.0\" --natpf1 \"guestssh,udp,,20000,,20000\"\n\r");

Edit Oh, I see now that you've changed the question. Now, I'm afraid I can't understand it. You want it to look at each line and stop when reaching "guestssh,udp,,20000,,20000" and print that to the file?

编辑哦,我现在看到你已经改变了问题。现在,我恐怕无法理解。你希望它看到每一行并在到达“guestssh,udp ,, 20000,,20000”时停止并将其打印到文件中?

Please elaborate on what you're trying to do.

请详细说明你要做的事情。

#4


0  

$content = "";
for($i=1;$i<=10000;$i++){
$content.="VBoxManage modifyvm "Elastix 4.0" --natpf1 \"guestssh{$i},udp,,{$i+10000},,{$i+10000}\"\n";
}
file_put_contents('file.txt', $content);

#1


1  

 <?php
  $fp = fopen("outfile.txt", "w");
  for($x = 10000; $x<=20000; $x++){
      fprintf($fp , 'VBoxManage modifyvm "Elastix 4.0" --natpf1 "guestssh%d,udp,,%d,,%d"'."\n", $x - 9999, $x, $x);
  }
  fclose($fp);

#2


1  

* is made to help you with your questions, not to code for you.

*旨在帮助您解决问题,而不是为您编写代码。

Anyway,

$output = '';
for ($i = 10001; $i <= 20000; ++$i) {
    $output .= 'VBoxManage modifyvm "Elastix 4.0" --natpf1 "guestssh,udp,,' . $i . ',,' . $i . '"' . PHP_EOL;
}

$f = fopen('commands.txt', 'w');
fwrite($f, $output);
fclose($f);

#3


0  

This is a simple solution using file_put_contents() for printing the text you wrote to a file called "this_is_my_txt_file.txt".

这是一个简单的解决方案,使用file_put_contents()将您写入的文本打印到名为“this_is_my_txt_file.txt”的文件中。

file_put_contents('this_is_my_txt_file.txt', "VBoxManage modifyvm \"Elastix 4.0\" --natpf1 \"guestssh,udp,,10001,,10001\" to VBoxManage modifyvm \"Elastix 4.0\" --natpf1 \"guestssh,udp,,20000,,20000\"\n\r");

Edit Oh, I see now that you've changed the question. Now, I'm afraid I can't understand it. You want it to look at each line and stop when reaching "guestssh,udp,,20000,,20000" and print that to the file?

编辑哦,我现在看到你已经改变了问题。现在,我恐怕无法理解。你希望它看到每一行并在到达“guestssh,udp ,, 20000,,20000”时停止并将其打印到文件中?

Please elaborate on what you're trying to do.

请详细说明你要做的事情。

#4


0  

$content = "";
for($i=1;$i<=10000;$i++){
$content.="VBoxManage modifyvm "Elastix 4.0" --natpf1 \"guestssh{$i},udp,,{$i+10000},,{$i+10000}\"\n";
}
file_put_contents('file.txt', $content);