• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Extracting a Number

Niaad

New Member
Ok, here's the latest ordeal I've gotten myself into...

The numbers I'm reading from a .html file are in this format:

##(##)

That is... 15(4).

Basically, what I need, is just the first two numbers in that example [the numbers before the (]. Ok, so that'd be easy with substr, but the problem is, the numbers aren't always the same length.

Sometimes it's 4(0). Sometimes it's 104(12).

Is there any other way to do this, so it works no matter what length the two numbers are?
 
Use a regular expression. Something like this would work:

($number)=($input=~/^(\d+)\(/);



<edit>

That's Perl, by the way. If you wanted it in something else, say what. Here it is in PHP, it's a bit more complicated:

preg_match("/^(\d+)/",$input,$out);$number=$out[0];
 
Last edited:
Oops, I should've mentioned I'm working with PHP :).

But thanks for the responses, I'll go try 'em out.
 
Back
Top