NETSYNC Posted October 21, 2010 Share Posted October 21, 2010 Hello all. I am finishing up a paypal IPN php script and was wondering how I can take some data and cut some of it off before I enter it into the mysql database? Heres what I have. $payment_date = HH:MM:SS DD Mmm YY, YYYY PST This comes from paypal. I want to in my code take that and automatically cut off the HH:MM:SS part. So my question is, how can I take a known piece of data and automatically trim the first 9 spots off of it? Something like: $payment_date = HH:MM:SS DD Mmm YY, YYYY PST Minus 1 thru 9 of $payment_date = $result $payment_date2 = $result Any help? Thanks! Quote Link to comment Share on other sites More sharing options...
marcus Posted October 21, 2010 Share Posted October 21, 2010 <?php $s = 'HH:MM:SS DD Mmm YY, YYYY PST'; $e = explode(' ',$s,2); $first_part = $e[0]; $secnd_part = $e[1]; ?> Quote Link to comment Share on other sites More sharing options...
NETSYNC Posted October 21, 2010 Author Share Posted October 21, 2010 Thanks very much for the reply and help. Let me see if I understand this. $s = 'HH:MM:SS DD Mmm YY, YYYY PST'; We are defining a variable to the data I pulled $e = explode(' ',$s,2); Are we here opening the data from above and saying at the first _space_ break it into 2? $first_part = $e[0]; $secnd_part = $e[1]; Here we are creating a variable for the first part and the second part from above. first part would be HH:MM:SS. Second part is the rest? I think I understand it. Let me know if I am on the right track. I am learning. =) Quote Link to comment Share on other sites More sharing options...
marcus Posted October 21, 2010 Share Posted October 21, 2010 What I did was took your example of the timestamp being used. You want to rid of the HH:MM:SS, so by splitting up your string (using explode) and limiting it to 2 outcomes we are able to make two separate strings, one that is HH:MM:SS and one that is DD Mmm YY, YYYY PST. Quote Link to comment Share on other sites More sharing options...
NETSYNC Posted October 21, 2010 Author Share Posted October 21, 2010 Thanks. But the only part I am trying to understand is, what determines WHERE it splits in 2? Is that what the " " is? Saying at the first SPACE? Quote Link to comment Share on other sites More sharing options...
marcus Posted October 21, 2010 Share Posted October 21, 2010 If we didn't use the third parameter of 2 in the explode call we would be splitting the string into n pieces when a string comes up. But since we only want 2 it will only split the string into 2 parts, one that is the data before the first space and another that is the data after the first space. Quote Link to comment Share on other sites More sharing options...
NETSYNC Posted October 21, 2010 Author Share Posted October 21, 2010 Thanks very much. I appreciate taking the time to help AND to explain it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.