Re: text formatting using eregi_replace

From: David (jaco2001uk_at_dontspamme.ntlworld.com)
Date: 11/29/03


Date: Sat, 29 Nov 2003 00:25:09 -0000


"Pedro Graca" <hexkid@hotpop.com> wrote in message
news:bq8mgi$1v17na$1@ID-203069.news.uni-berlin.de...
> David wrote:
> > When you run a query for the system uptime the result is displayed like
so:
> >
> > Timeticks: (4592345) 12:45:23.45
> >
> > 1.) I would like to remove the first two "fields" so I am left with:
> > 12:45:23.45
> >
> > I have managed to remove the Timeticks: part but don't know how to
remove
> > the (4592345) (because this is of variable size).
> >
> > $sysuptime = eregi_replace("Timeticks: ","",$sysuptime);
> >
> > I don't know if it is possible but could you say remove everything
within
> > the brackets - is that possible in a regular expression?
>
> switch to preg_* (info @ http://www.php.net/PCRE)
> these functions (supposedly) are faster and more powerful
>
> $sysuptime = preg_replace('@Timeticks: \(\d+\) @', '', $sysuptime);
>
> comments:
> @ start the regex (you can use other characters)
> Timeticks: and a space are matched verbatim
> \( one verbatim "("
> \d+ one or more digits
> \) verbatim ")"
> space another space
> @ end the regex
>
> the parentheses had to be escaped (with the backslash character) because
> they have a special meaning in regular expressions.
>
>
> > 2.) If possible I would like to convert the output 12:45:23.45 to
something
> > more like 12hr 45 mins
>
> For just the hours example I'd probably use substr():
> $sysuptime = substr($sysuptime, 0, 2) . 'hr '
> . substr($sysuptime, 3, 2) . ' mins';
>
> > Obviously as the uptime increases that needs to incorporate _days_ as
well.
>
> Well ... maybe a regexp is better :-)
> Have a go at it. If you have problems report back here.
>
>
> > 3. Is it good/bad practice to use the same variable name twice in the
> > statement above?
>
> I use it all the time (when that is what I want, of course).
> If it weren't ok to use they would never have invented the ++ or --
> things!
>
> $a++; // short way to use the same var on both sides of the = sign :)
>
>
> HTH
> --
> --= my mail address only accepts =--
> --= Content-Type: text/plain =--
> --= Size below 10K =--

Pedro,

Thank you for the help. I understand the regexp you used in 1.) above.
Excellent explanation.

I will certainly try and workout how to do 2.)

:)

David



Relevant Pages

  • Re: Open a form from a record in Querry result or Table
    ... David assume for our discussion that you have a form and it is set to ... datasheet view and this form is based on the select query you mentioned ... the first form so that it opens your tab form and only display the one ... Private Sub Form_DblClick ...
    (microsoft.public.access.gettingstarted)
  • Re: ADVANCED: Suppressing "Save Layout?" dialog on form close
    ... I have the "Allow Design Changes" property set to ... Since the fields inside the query always load with the same width, ... OnUnload events both on the query's datasheet and the form but when the ...
    (microsoft.public.access.formscoding)
  • Re: Correlated Query problem with large tables
    ... I get the green 'Running Query' message which fills to ... "david epsom dot com dot au" wrote: ... I'm trying find out stock numbers from ReducedStockList that Customers ...
    (microsoft.public.access.queries)
  • Re: Index Seek (or) Index Scan in Execution Plan
    ... > Prabhat wrote: ... >> Thanks David for your Suggestion. ... run a simpel query on the table ... > by a bookmark lookup operation (you need to include the second unindexed ...
    (microsoft.public.sqlserver.server)
  • Re: Index Seek (or) Index Scan in Execution Plan
    ... > Prabhat wrote: ... >> Thanks David for your Suggestion. ... run a simpel query on the table ... > by a bookmark lookup operation (you need to include the second unindexed ...
    (microsoft.public.sqlserver.programming)