![]() Preserved Topic: PHP file search and regexps (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: New Jersey, USA |
![]() I'm trying to write a script in PHP that opens a directory, picks out the files with a html file name, and then searches each of those files for .gif or .jpeg file names. The return for the image file names needs to be the whole path (i.e. src="images/showtime/winners/topleft_01.gif") only without the *src=* or the parentheses at either end. I've gotten as far as opening the directory, and extracting all the html files, opening a file and read it. I don't know what function to use to look through the file with the regexp (which I need help with also) to extract the .gif or .jpeg path names. Here's what I have so far: |
Maniac (V) Mad Scientist From: Belgrade, Serbia |
![]() Here you go: |
Paranoid (IV) Inmate From: New Jersey, USA |
![]() Thanks Mr. Max, Works like a charm. |
Paranoid (IV) Inmate From: Minneapolis, MN, USA |
![]() Regular Expressions are really not all that complicated, they just look that way. Try man grep in your unix shell for an explanation, or search around the net, most explanations are less than complete given the wide range of versatility and special cases possible. If you have a Mac, BBEdit has a very good explanation. |
Paranoid (IV) Inmate From: New Jersey, USA |
![]() Thanks jiblet. I appreciate you taking the time for such a complete response. |
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
![]() Just to answer the question about the "\$" This is backslashed, like the quotes, for PHP (I'm assuming) not the regexp otherwise PHP will start looking for a variable called "$/i" and probably break. |
Maniac (V) Mad Scientist From: Belgrade, Serbia |
![]() Bitdamaged is right. "preg*" functions are only wrappers for their counterparts in PCRE library, and PHP is passing them a string that is parsed first by PHP and after that by PCRE library. So, if in some case you really need to escape a special RegEx character, you'll have to use double backslash. |
Paranoid (IV) Inmate From: Minneapolis, MN, USA |
![]() What implementation of Regexps isn't greedy by default? Perl? |
Maniac (V) Mad Scientist From: Belgrade, Serbia |
![]() |