title: how to split the variable input by users to an array
body: <p>A variable $irn input by the users, I need to pass the variable $irn one by one to a SQL and display the result in GR textbox after clicking the button
  Generate Result, I want to split the $irn to an array so I can pass it one by one to the SQL query.</p>
  
  <p>I tried mb_split and preg_split</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  include "big2gb.php";
  
  ini_set('default_charset', 'utf-8');
  
  $result = $_GET["listIRN"];
  $irn = $_POST["irn"];
  
  $serverName = "192.168.4.75";
  
  $connectionInfo = array( "Database"=&gt;"SAFHKG", "UID"=&gt;"sa1", "PWD"=&gt;"Azsxdc11", "CharacterSet" =&gt; "UTF-8");
  $conn = sqlsrv_connect( $serverName, $connectionInfo );
  
  if($conn){
     //echo "connect DB success!!!&lt;br /&gt;";
           }
     else
     {
               //echo "successfully failed!!!&lt;br /&gt;";
               die(print_r(sqlsrv_errors(),true));
     }  
  //find irn   
  $sql="Select Top 1
  [Expression] = CONCAT(OFFICIALNUMBER, ' for ', TITLE, ' in Class ', LOCALCLASSES)
  From CASES
  INNER JOIN OFFICIALNUMBERS On CASES.CASEID = OFFICIALNUMBERS.CASEID
  Where NUMBERTYPE IN ('R', 'A') and CASES.IRN = ('".$array[$i]."')
  Order By
  CASE 
   When NumberType = 'R' then -2
   When Numbertype = 'A' then -1
  End";
  
  echo"
  &lt;table&gt;
    &lt;form action='test22.php' method='post'&gt;  
   &lt;tr&gt;
      &lt;td&gt;IRN:&lt;/td&gt;
      &lt;td&gt;
   &lt;input type='text' id='txtIRN' value='' style='text-transform:uppercase' &gt;
   
   &lt;input type='button' value='Add IRN' onClick='addIRN()' name=''/&gt;
   
   &lt;input type='submit' value='Genarate Result' id='GR' name=''/&gt;
   &lt;/td&gt; 
   &lt;/tr&gt;
   &lt;tr&gt;&lt;tr&gt;&lt;tr&gt; 
   &lt;td&gt;&lt;td&gt;
   &lt;textarea id='listIRN' name='irn' rows='40' cols='30' &gt;
   
   &lt;/textarea&gt;&lt;textarea id='GR' rows='40' cols='80' &gt;&lt;/textarea&gt;
   &lt;/td&gt;&lt;/td&gt;
   &lt;/tr&gt;&lt;/tr&gt;&lt;/tr&gt;  
    &lt;/form&gt; 
  &lt;/table&gt;&lt;br/&gt;";
  
  echo"
  &lt;script type='text/javascript'&gt;
  function addIRN(irn) {
      var IRNText = document.getElementById(\"txtIRN\").value;
   var IRNList = document.getElementById(\"listIRN\").value;
   
   var irn = IRNList + '\\n' + IRNText;
   
   document.getElementById(\"listIRN\").value = irn.trim().toUpperCase();
  }
  &lt;/script&gt;";
  //////////////////your entered//////////////////*
     echo "&lt;p&gt;You entered:&lt;p&gt;";
    $array = mb_split('\\n', $irn);
     foreach($array as $line)
     {
     $array = explode('\s', $irn); 
        echo "$line\n";
     }  
  //////////////////////////////////////////////
  
  
  print_r ($array); 
  
  //echo $array[3];
  //echo $array[0];
  
  
  for ($i = 0; $i &lt;= 20; $i++) 
  {     
  $result = sqlsrv_query($conn, $sql );
  
   while( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOc) )
   {
    echo " ". $row["Expression"] ." &lt;br /&gt;";
   }
  }
  
  $conn-&gt;close(); 
  
  ?&gt;</code></pre>
  </div>
  </div>
  strong text</p>
  
  <p>User input will be like TM1150CN31 TM2846CN35 TM2855CN35 TM2865CN35 TM2874CN43 TM3367CN05</p>