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!

 

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.