Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    377
    Rep Power
    76

    Help with (explode)


    I am trying to record a part of this string. Should I format this some other way?

    PHP Code:

    1
    ,1,1,some text here,ABCD,Y,55678759949,FGRTUD  <<<string

    $split = explode(',', $xml->directResponse[6]);
    $txnid = $split[6];

    $txnid should equal '55678759949' but it doesn't like that format for some reason. If I put $txnid ="1234"; my page will save it with that value. 
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    First of all, remove the unnecessary stuff from inside your php tags in your post, the whole thing is malformed.

    Now, if you're saying that you've printed a string and verified it to be:
    $yourString = ' 1,1,1,some text here,ABCD,Y,55678759949,FGRTUD';

    Then this:
    $pieces = explode(',', $yourString);

    Would result in '55678759949' being in $pieces[6];

    Have you verified the contents of the string, the contents of the exploded array, or anything else?

    This is how debugging works. Print the string. is it correct? print the array. is it correct? print the resulting value. is it correct? continue until there are no more problems.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    377
    Rep Power
    76
    Yes I have verified 55678759949 is directResponse[6];

    and I have echoed it and printed that number. I can get any of those parts. My question is this part.

    $txnid = $split[6]; //does't work
    $txnid = "55678759949"; //works

    PHP Code:
    Thank you for your help 
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    Var_dump this value and make sure it's a string of the proper length. Maybe you have a space.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    377
    Rep Power
    76
    Yes I var_dumped and have the correct places. The value is correct just that $txnid doesn't get the value assigned to it unless I hard code the number. I thought maybe something is missing a bracket or quotes.
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    var_dump($split[6]);

    See if it's the right number of characters.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    377
    Rep Power
    76
    I get NULL on var_dump($split[6]); If I var_dump($txnid); I get the number.

    the string comes from a XML reply

    <directResponse>1,1,1,some text here,ABCD,Y,55678759949,FGRTUD</directResponse>



    If I echo $xml->directResponse I will get 1,1,1,some text here,ABCD,Y,55678759949,FGRTUD



    I need $txnid to hold the value of 55678759949
  14. #8
  15. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    I need $txnid to hold the value of 55678759949
    But you said...
    If I var_dump($txnid); I get the number.
    Either your problem is solved, or one of us is not understanding what's happening.

    Change your script to this. Copy and paste the results here:
    PHP Code:
    var_dump($xml->directResponse[6]);echo "\n<br />\n";
    $split explode(','$xml->directResponse[6]); 
    var_dump($split);echo "\n<br />\n";
    var_dump($split[6]);echo "\n<br />\n";
    $txnid $split[6]; 
    var_dump($txnid);echo "\n<br />\n"
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    377
    Rep Power
    76
    I get 3 NULLs and
    array(1) { [0]=>string(0) ""


    Since the $xml->directResponse is in the same class but from a different method should I be using parent::
  18. #10
  19. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    So you never verified if $xml was even set?

    If $xml is created in some other function, it is not accessible to this function.

    You need to either pass it into this function or set it to a variable on $this.

    Wherever $xml is CREATED, change all the references to $this->xml

    Then, in the function you've shown us, use $this->xml

    More information can be found in the manual under "Variable Scope"
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    377
    Rep Power
    76
    Ok that is starting to make sense. I figured since they were in different methods it couldn't be shared. Here are the two methods process() and build()

    PHP Code:
        function process () {
            global 
    $Mycart;
            
    $message $this->build();
            
    $Response $this->send($message);
            
            
            if (
    $status == "2" || $status == "4"){ 
        
                
    $message $xml->messages->message->code;
                
                
    $code $splitted[0];
                
                if (empty(
    $message)) { 
                    new 
    MycartError(__("A configuration error occurred while processing this transaction. Please contact the site administrator.","Mycart"),'authnet_error',MYCART_TRXN_ERR);
                    
                    return;
                }
                new 
    MycartError($xml->messages->message->code,'authnet_error',MYCART_TRXN_ERR);
                    
    var_dump($xml->messages->message->code);
                    
                    return;
            }
            
            
            

            
    $txnstatus $xml->messages->resultCode
            
            
    $Mycart->Order->transaction($txnid,$txnstatus);

        }
        

        

        function 
    build () {
        
    $Order $this->Order;
        

     
        
    $xml = new AuthnetXML(AUTHNET_LOGINAUTHNET_TRANSKEYAuthnetXML::USE_DEVELOPMENT_SERVER);
        
    $xml->createCustomerProfileTransactionRequest(array(
          
    'transaction' => array(
                
    'profileTransAuthCapture' => array(
                    
    'amount' => '10.95',
                    
    'tax' => array(
                        
    'amount' => '1.00',
                        
    'name' => 'your state sales tax',
                        
    'description' => 'description state sales tax'
                    
    ),
                    
    'shipping' => array(
                        
    'amount' => '2.00',
                        
    'name' => 'ground based shipping',
                        
    'description' => 'Ground based 5 to 10 day shipping'
                    
    ),
                    
    'lineItems' => array(
                        
    => array(
                            
    'itemId' => '1',
                            
    'name' => 'widget',
                            
    'description' => 'description of widget',
                            
    'quantity' => '18',
                            
    'unitPrice' => '45.00'
                        
    ),
                        
    => array(
                            
    'itemId' => '2',
                            
    'name' => 'widget2',
                            
    'description' => 'description widget 2',
                            
    'quantity' => '10',
                            
    'unitPrice' => '85.00'
                        
    )
                    ),
                    
    'customerProfileId' => '129',
                    
    'customerPaymentProfileId' => '169',
                    
    'customerShippingAddressId' => '120',
                    
    'order' => array(
                        
    'invoiceNumber' => 'INV55',
                        
    'description' => 'description of transaction',
                        
    'purchaseOrderNumber' => 'PON55'
                    
    ),
                    
    'taxExempt' => 'false',
                    
    'recurringBilling' => 'false',
                    
    'cardCode' => '000'
                
    )
            ),
         
            
        ));

    echo 
    "Response: " $xml->messages->message->code  "<br><br>";//Ok
    echo "Code: " $xml->messages->resultCode .  "<br><br>";// number
    echo "Text: " $xml->messages->message->text .  "<br><br>"//Successful

    return $xml;//end function

     

    Would I pass $xml to the method like this?
    PHP Code:
    function process ($xml
  22. #12
  23. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    $message = $this->build();

    That says "take the result of $this->build() and put it into the variable $message."

    You have that, you HAVE the message.

    However, you then 5 lines later use $xml. You do NOT have $xml. $message is the XML message, it's what you got when you ended build() with:

    return $xml;

    Just use $message.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    377
    Rep Power
    76
    Ok so like this?

    PHP Code:
    function process ($message) {........


    $this->$split explode(','$xml->directResponse[0]); 
    var_dump($this->$split);echo "\n<br />\n";
    echo 
    var_dump($this->$split[6]);echo "\n<br />\n";
    $this->$txnid $this->$split[6]; 
    var_dump($this->$txnid);echo "\n<br />\n"
  26. #14
  27. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    No...not even a little bit.

    You really need to just read the article on variable scope. Look here:

    PHP Code:
    function process () { 
            global 
    $Mycart
            
    $message $this->build(); 
            
    $Response $this->send($message); 
             
             
            if (
    $status == "2" || $status == "4"){  
         
                
    $message $xml->messages->message->code
    $message is the XML result from the build() function.

    You then check $status, which doesn't exist.

    Then you re-assign $message to be some subset of $xml, which doesn't exist.

    Most of the variables you use don't exist in the context you're trying to use them in.

    You're also running without error-reporting. At the top of your script, put:

    error_reporting(E_ALL);

    Then run your page. You'll see dozens, if not hundreds, of errors relating to these missing variables.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    377
    Rep Power
    76
    Thanks the error reporting helps. I agree the variables don't exist in the process() method. I am trying to get them from the build() method. I am able to echo the values from the build () method.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo