douhanshu5517 2012-03-11 21:28
浏览 30
已采纳

每行读取文本框输入并在php中执行for循环以进行卷曲

I do have an html form that accepts textbox input of sha1 hashes per line:

    <textarea id="mid "name="mid" cols="40" rows="5"></textarea>

Example values are:

    9a3845cf0aac825d4e754610baa473f53636f10a
    9a3845cf0aac825d4e754610baa473f53636f10b
    9a3845cf0aac825d4e754610baa473f53636f10c

My problem is I need to take each value from the textbox "per line" and pass it to curl, my code below works only on a single entry basis:

    <?php
    $pf="pf";
    $ur="ur";
    $pw="pw";
    $url="url.com";
    extract($_POST);
    $mid=$_POST['mid'];

    $fields = array(
        'user'=>urlencode($ur),
        'pass'=>urlencode($pw),
        'pfid'=>urlencode($pf),
        'msid'=>urlencode($mid)
    );

    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string,'&');

    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST,count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
    $result=curl_exec($ch);
    curl_close($ch);
    ?>

My expected output from the curl'ed server are the results of all those from the textbox:

    9a3845cf0aac825d4e754610baa473f53636f10a - okay
    9a3845cf0aac825d4e754610baa473f53636f10b - cancelled
    9a3845cf0aac825d4e754610baa473f53636f10c - okay

Any thoughts? Thanks in advance!

  • 写回答

2条回答 默认 最新

  • dqby43944 2012-03-11 21:31
    关注

    explode on the new line character:

    $mids = explode("
    ", $mid);
    

    Then you can access each line:

    foreach ($mids as $mid){
        // ... etc
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致