Jump to content

[SOLVED] Display specifc field from explode string


jaxdevil

Recommended Posts

Ok, I am trying to display a single field from an explode string. I have no idea how to do this. The script already explodes the string and loops the data displaying it in table format..

 

      // load a temporary array with the values returned from authorize.net
      $temp_values = explode('|', $this->response_string);

      // load a temporary array with the keys corresponding to the values 
      // returned from authorize.net (taken from AIM documentation)
      $temp_keys= array (
           'Version','ResponseCode','Code','Description','AuthCode', 'AVSResultCode','CVVResultCode','TransID','RefTransID','TransHash','TestMode',''	
      );

 

The above code is what explodes the string and labels it. the below code is what makes the loop which displays the data in table format...

 

   function dump_response() {

      // Used for debuggin, this function will output all the response field
      // names and the values returned for the payment submission.  This should
      // be called AFTER the process() function has been called to view details
      // about authorize.net's response.
      
      echo "<h3>authorizenet_class->dump_response() Output:</h3>";
      echo "<table width=\"95%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">
            <tr>
               <td bgcolor=\"black\"><b><font color=\"white\">Index </font></b></td>
               <td bgcolor=\"black\"><b><font color=\"white\">Field Name</font></b></td>
               <td bgcolor=\"black\"><b><font color=\"white\">Value</font></b></td>
            </tr>";
            
      $i = 0;
      foreach ($this->response as $key => $value) {
         echo "<tr>
                  <td valign=\"top\" align=\"center\">$i</td>
                  <td valign=\"top\">$key</td>
                  <td valign=\"top\">$value </td>
               </tr>";
         $i++;
      } 

 

Now what I am trying to do is display JUST the AuthCode. I duplicated the loop foreach string and it displays everything in one line. Here is the code..

 

      $i = 0;
      foreach ($this->response as $key => $value) {
         echo "<tr>
                  <td valign=\"top\" align=\"center\">$i</td>
                  <td valign=\"top\">$key</td>
                  <td valign=\"top\">$value </td>
               </tr>";
         $i++;
      } 

 

And the output it displays is...

0 Version 1.0  1 ResponseCode 1  2 Code 1  3 Description (TESTMODE) This transaction has been approved.  4 AuthCode 000000  5 AVSResultCode P  6 CVVResultCode  7 TransID 0  8 RefTransID B01BFA1E733BC8491FB07B8586783EF6  9 TransHash 

 

Anyone know how I can make the field number 4 (AuthCode) display on its own? I want to make it display in a form that I can update a database with. I have that part covered, I just need to find out how to get just that field to display. Thanks in advance guys!

Link to comment
Share on other sites

you could do this

 

 

    //data array 
      $arrData = array();
      // load a temporary array with the values returned from authorize.net
      $temp_values = explode('|', $this->response_string);

      // load a temporary array with the keys corresponding to the values 
      // returned from authorize.net (taken from AIM documentation)
      $temp_keys= array (
           'Version','ResponseCode','Code','Description','AuthCode', 'AVSResultCode','CVVResultCode','TransID','RefTransID','TransHash','TestMode',''	
      );

      for ($i=0;$i<count($temp_keys);$i++)
      {
  $arrData[$temp_keys[$i]] = $temp_values[$i];
      }

      //then you could do this 

      echo $arrData['Version'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.