views:

31

answers:

3

Simply put,

I have a string with a prefix "msg" followed by some numbers that serve as the ID for a list item

e.g.

<li id="msg1"></li>..............<li id="msg1234567890"></li>

What is the most efficient way to grab just the numbers?

In VB, I'd do the following:

str = "msg1" str = right(str,len(str)-3)

How would I do something similar (or more efficient) in PHP?

+1  A: 

Just use preg:

preg_match_all('%<li id="msg(\d+)"></li>%i', $subject, $result, PREG_PATTERN_ORDER);
Blizz
I think it's better to use this method, with regex, because if you have an id with 4 letters at the beginning, the other method with substr won't work properly
Squ36
+3  A: 

the same in php (using substr):

$str = "msg1";
$str = substr($str,3);
oezi
A: 

substr( $string, 3 );

See http://ca3.php.net/manual/en/function.substr.php

Homer6