Welcome to WebmasterWorld Guest from 54.226.2.31

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

using regex to extract data

or any other method ...

     

irubin

1:22 am on Sep 11, 2003 (gmt 0)

10+ Year Member



Hello,

How can I extract the number 19 from the string product_27001_th19.jpg . The solution needs to be dynamic, as the function should return 19 for all the following:

product_2_th19.jpg
product_gf_th19.jpg
product_2704401_th19.jpg

I am perl programmer and not sure how to do this in php.

Thanks.

Roy

moltar

1:40 am on Sep 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1) Do you want it in PHP or Perl? This is a Perl forum.
2) What do you want to do with 19 later? If you just want to extract 19 whats the point? It'a always 19...

Am I missing something?

myself

8:13 am on Sep 11, 2003 (gmt 0)

10+ Year Member



If '19' appers only before dot that separates filename from extention than you may try this code in perl:

my ($number) = $filename =~ m/(\d+)\.[^.]+$/;

Here $filename must contain your filename, and $number receives '19' or any other number that was in filename.

.....
update: oops, you wish to do that in php....

 

Featured Threads

Hot Threads This Week

Hot Threads This Month