RE: [PHP] Re: converting C to PHP
| From: | Martin Towell | Date: | Thu, 13 Jun 2002 05:24:31 +0000 |
| Subject: | RE: [PHP] Re: converting C to PHP | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-101902@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: David Robley [mailto:robleyd@paradise.net.nz]
> Sent: Thursday, June 13, 2002 3:25 PM
> To: php-general@lists.php.net
> Subject: [PHP] Re: converting C to PHP
>
>
> In article <6416776FCC55D511BC4E0090274EFEF508A46F@EXCHANGE>,
> martin.towell@world.net says...
> > I'm converting some C functions to PHP and have come across this:
> >
> > int skipf(..., char *format)
> > {
> > /* ... */
> > cp = format;
> > char *cp, *cp2;
> > multiplier = strtol(cp, &cp2, 10);
> > /* ... */
> > }
> >
> >
> > How can I implement this line in PHP ?
> > multiplier = strtol(cp, &cp2, 10);
> >
> >
> > > Oh, and an example of format is "12L20W2P"
>
> Non C programmer volunteers suggsetion. I looked at strtol in the C docs
> and I don't quite understand exactly what it does. But I wonder if intval
> would be a starting point to try and get the result I think you want?
>
> --
> David Robley
> Temporary Kiwi!
>
> Quod subigo farinam
Just to crarify - what I need to get back is the first number and the first
letter after that number (which can be "L", "P", or "W"). So in the
example
I gave, I'll need to get back "12" and "L"
What I settled on is:
ereg("([0-9]*)([LPW])", $format, $bits);
list(, $cnt, $skip) = $bits;
But maybe there's a better way ??
Martin