This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

strip times

Old posts that have not been replied to for several years.
Locked
w
w0t

strip times

Post by w0t »

hi,

i'm working on this for hours but no success
i want strip the time from a string
samples:
xxx was here 1 hour and 3 seconds ago
xxx last seen 1 week 5 days 3 hrs 5 mins 1 sec
xxx was online 5mins 3sec ago
--

i only need the time .. -> 1 hour 3 seconds
or 1 week 5 days 3 hrs 5 mins 1 sec

how can i strip this parts from the string

regards w0t
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

You call those 3 things "samples", and each one has a different format. Are those all of the formats, or are there more? If those are it, it's really easy, just use regexp to get the text between "was here" and "ago", for instance.

Code: Select all

regexp {was here (.*) ago} $text match thetime
# now $thetime is "1 hour and 3 seconds"
Similar for "last seen" and "was online" too.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

stdragon wrote:You call those 3 things "samples", and each one has a different format. Are those all of the formats, or are there more? If those are it, it's really easy, just use regexp to get the text between "was here" and "ago", for instance.

Code: Select all

regexp {was here (.*) ago} $text match thetime
# now $thetime is "1 hour and 3 seconds"
Similar for "last seen" and "was online" too.
Better:

Code: Select all

regexp { ([0-9].*)} $text garbage thetime
w
w0t

Post by w0t »

thanks . works like a charm ...
Locked