How's the PHP picking out only those going in a certain order?



  • How to choose the lines (read from the file) where it comes first:

    1. First 'translatedUpload' or 'SUpload'
    2. then 'name'
    3. Then 'ftpServer'

    That's the lines where there's no such order.

    string(10) "<Upload"
    string(19) "name = events"
    string(36) "ftpServer = s1.ru"
    string(10) "<SUpload"
    string(16) "name = s33"
    string(36) "ftpServer = 192.168.0.68"
    string(16) "name = name1"
    string(25) "name = name22_test"
    string(10) "<Upload"
    string(19) "name = name44"
    string(36) "ftpServer = 192.168.0.69"
    

    It shall be:

    string(10) "<Upload"
    string(19) "name = events"
    string(36) "ftpServer = s1.ru"
    string(10) "<SUpload"
    string(16) "name = s33"
    string(36) "ftpServer = 192.168.0.68"
    string(10) "<Upload"
    string(19) "name = name44"
    string(36) "ftpServer = 192.168.0.69"
    


  • Put it in the mass, run through the mass and take it. Somehow:

    for( $i=0; $i<count($lines)-2; $i++){
        if( preg_match('/<S?Upload/', $lines[$i] && preg_match('/name/', $lines[$i+1] && preg_match('/ftpServer/', $lines[$i+2] ){
            $result[]=$lines[$i];
            $result[]=$lines[$i+1];
            $result[]=$lines[$i+2];
        }
    }
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2