homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
using regex to extract data
or any other method ...
irubin




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

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




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

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




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

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....

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved