Forum Moderators: coopster

Message Too Old, No Replies

preg match

match number in string

         

ayushchd

10:58 pm on Jun 12, 2010 (gmt 0)

10+ Year Member



Hi all!

Inside a text, there is a part like this - /db/images/7236.jpg

I want to extract the number from the text!

What could be the correct syntax?

Thank in advance

Readie

11:20 pm on Jun 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[pre]preg_match('/^.*?(\/[^\/]+)*\/([\d]+)\..+$/', $input, $out);
echo $out[1];[/pre]

Should do it

ayushchd

6:18 am on Jun 13, 2010 (gmt 0)

10+ Year Member



there are other similar texts too, but I want the text that has a numerical file name

/db/images/7236.jpg
/db/images/ab.jpg
/db/images/cd.jpg


I want the output to be 7236