doubi5127 2014-07-10 16:09
浏览 11
已采纳

我应该使用php返回rexecuta脚本

So... I'm a newbie in php and I want to read every line from a file, execute my script and then cameback to read a new line and execute again the script. My script is about reading links from a target specified so I decided to make it to read a target from a file to learning something new.

Here's my code for reading every lines from a file

<?
$handle = fopen("targets.txt", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        echo $line;
    }
} else {
    echo "Can't open the file.";
} 
fclose($handle);
?>

and here is the script code:

$site = "http://www.example.com";

...script code...

so basicly I want for my $site variable to be every line from target.txt I tried to implement both like $site = "$line"; but it give me errors and I read something about return command... how should I build for my example?

  • 写回答

1条回答 默认 最新

  • douyeyan0650 2014-07-10 16:16
    关注

    IT sounds like you should be using a function:

    <?php
    $handle = fopen("targets.txt", "r");
    if ($handle) {
      while (($line = fgets($handle)) !== false) {
        $line = do_something( $line );
        echo $line;
      }
    } else {
      echo "Can't open the file.";
    } 
    fclose($handle);
    
    function do_something( $line ) {
    
      // do something with $line...
    
      return $line;
    }
    

    Notice that with this type of function declaration you must return the value you created within your function and re-assign it back to the "source" variable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 14名同学选出十名到西和,礼县,武都宕昌参加实习,每个学校一个人
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路