Re: text formatting using eregi_replace
From: David (jaco2001uk_at_dontspamme.ntlworld.com)
Date: 11/29/03
- Next message: Michael Fuhr: "Re: Question about putenv()"
- Previous message: Pedro Graca: "Re: text formatting using eregi_replace"
- In reply to: Pedro Graca: "Re: text formatting using eregi_replace"
- Next in thread: David: "Re: text formatting using eregi_replace"
- Reply: David: "Re: text formatting using eregi_replace"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Michael Fuhr: "Re: Question about putenv()"
- Previous message: Pedro Graca: "Re: text formatting using eregi_replace"
- In reply to: Pedro Graca: "Re: text formatting using eregi_replace"
- Next in thread: David: "Re: text formatting using eregi_replace"
- Reply: David: "Re: text formatting using eregi_replace"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|