Jump to content

How to truncate some of data before entry into database?


NETSYNC

Recommended Posts

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!

 

Link to comment
Share on other sites

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.  =)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.