• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

regex question

Does anyone know how I get can the quoted code into an array with just the filenames with PHP/regex.

desiered aray: array(0 => 'tn_21-b196054175f.jpg', 1 => 'tn_21-b196054175.jpg' ... n => 'nth_filename.jpg')

So basically the array just has the filenames from all of the <img> tags (the number of img tags varies, igoring the directory paths and the href.

Thanks!
<a rel="rokzoom" href="components/com_productbook/img_originals/21-b196054175f.jpg">
<img src="components/com_productbook/img_thumbnails/tn_21-b196054175f.jpg" alt="" /></a>
<a rel="rokzoom" href="components/com_productbook/img_originals/21-b196054175.jpg">
<img src="components/com_productbook/img_thumbnails/tn_21-b196054175.jpg" alt="" /></a>
.
.
.
<a rel="rokzoom" href="components/com_productbook/img_originals/nth_filename.jpg">
<img src="components/com_productbook/img_thumbnails/nth_filename.jpg" alt="" /></a>

Open in new window

0
burnsj2
Asked:
burnsj2
  • 2
  • 2
1 Solution
 
tomasgruenerCommented:
Try to adapt following:
If you want to have the directory names:
src="([^.]*.jpg)"
If you just want to have the filenames try following pattern:
src=".*\/([^.|^\/]*.jpg)"

I tested it with your source snippet on http://www.regex-tester.de/regex.html and it worked fine
0
 
tomasgruenerCommented:
Oh, I hope you are familiar a bit with regex, how you do the php specific stuff... i havent coded php since years and I'm not very sure, how to use regex on php. but that should be easy.
0
 
burnsj2Author Commented:
This does not seem to work with PHP who's regex's are perl compatible.

My current code:
preg_match_all('src=".*\/([^.|^\/]*.jpg)"',$note,$altResults,PREG_PATTERN_ORDER);
print_r($altResults);

where $note is the input text in the original question. print_r outputs: Array( )
0
 
burnsj2Author Commented:
This regex does seem to work on some platforms, so I'm closing this and will post for a PHP specifc answer.
Thanks,
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now